<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>AJ</title>
    <meta name="generator" content="VuePress 1.5.0">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <script>
            var _hmt = _hmt || [];
            (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?51b8c2e72d1adf96524638ce85bb7d72";
            var s = document.getElementsByTagName("script")[0]; 
            s.parentNode.insertBefore(hm, s);

            // 引入谷歌,不需要可删除这段
            var hm1 = document.createElement("script");
            hm1.src = "https://www.googletagmanager.com/gtag/js?id=G-B7351EYS04";
            var s1 = document.getElementsByTagName("script")[0]; 
            s1.parentNode.insertBefore(hm1, s1);
            })();

            // 谷歌加载,不需要可删除
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());

            gtag('config', 'G-B7351EYS04');
        </script>
    <meta name="description" content="阿俊博客|记录一个程序员的成长历程 阿俊博客(blog.zhequtao.com)记录一个后端程序员的成长历程,分享他的学习笔记和心得,还有些开发必备技巧哦! java golang web html dev开发">
    <link rel="preload" href="/assets/css/0.styles.a3df589e.css" as="style"><link rel="preload" href="/assets/js/app.cb35c8f6.js" as="script"><link rel="preload" href="/assets/js/2.063846a6.js" as="script"><link rel="preload" href="/assets/js/4.1ffb4609.js" as="script"><link rel="preload" href="/assets/js/255.64e680cb.js" as="script"><link rel="prefetch" href="/assets/js/10.5629fe4d.js"><link rel="prefetch" href="/assets/js/100.8417ccea.js"><link rel="prefetch" href="/assets/js/101.37fdb377.js"><link rel="prefetch" href="/assets/js/102.848b686d.js"><link rel="prefetch" href="/assets/js/103.6a2489a0.js"><link rel="prefetch" href="/assets/js/104.99e8899f.js"><link rel="prefetch" href="/assets/js/105.8b741763.js"><link rel="prefetch" href="/assets/js/106.08163715.js"><link rel="prefetch" href="/assets/js/107.21801349.js"><link rel="prefetch" href="/assets/js/108.e3a2892b.js"><link rel="prefetch" href="/assets/js/109.dab5618c.js"><link rel="prefetch" href="/assets/js/11.cddc1623.js"><link rel="prefetch" href="/assets/js/110.f5249b39.js"><link rel="prefetch" href="/assets/js/111.9abf8bce.js"><link rel="prefetch" href="/assets/js/112.8eb86924.js"><link rel="prefetch" href="/assets/js/113.c180ed46.js"><link rel="prefetch" href="/assets/js/114.2370f5b5.js"><link rel="prefetch" href="/assets/js/115.88dc3fd8.js"><link rel="prefetch" href="/assets/js/116.63403600.js"><link rel="prefetch" href="/assets/js/117.83674aa0.js"><link rel="prefetch" href="/assets/js/118.9c58c685.js"><link rel="prefetch" href="/assets/js/119.621f9a70.js"><link rel="prefetch" href="/assets/js/12.ff3d03f5.js"><link rel="prefetch" href="/assets/js/120.a6d2b7f7.js"><link rel="prefetch" href="/assets/js/121.ae0ce9d1.js"><link rel="prefetch" href="/assets/js/122.de240e6d.js"><link rel="prefetch" href="/assets/js/123.b043e3e4.js"><link rel="prefetch" href="/assets/js/124.550af937.js"><link rel="prefetch" href="/assets/js/125.6f06b34c.js"><link rel="prefetch" href="/assets/js/126.38d64604.js"><link rel="prefetch" href="/assets/js/127.a948db56.js"><link rel="prefetch" href="/assets/js/128.4ca789e0.js"><link rel="prefetch" href="/assets/js/129.59be4505.js"><link rel="prefetch" href="/assets/js/13.e9f75cc3.js"><link rel="prefetch" href="/assets/js/130.ddae76a9.js"><link rel="prefetch" href="/assets/js/131.d969c265.js"><link rel="prefetch" href="/assets/js/132.5f43ce5c.js"><link rel="prefetch" href="/assets/js/133.b651af22.js"><link rel="prefetch" href="/assets/js/134.2499236a.js"><link rel="prefetch" href="/assets/js/135.4180596c.js"><link rel="prefetch" href="/assets/js/136.2c309233.js"><link rel="prefetch" href="/assets/js/137.72ca42dd.js"><link rel="prefetch" href="/assets/js/138.3772cd38.js"><link rel="prefetch" href="/assets/js/139.1d0a53da.js"><link rel="prefetch" href="/assets/js/14.be4b89ed.js"><link rel="prefetch" href="/assets/js/140.22368353.js"><link rel="prefetch" href="/assets/js/141.a14aef3c.js"><link rel="prefetch" href="/assets/js/142.2041ce3a.js"><link rel="prefetch" href="/assets/js/143.377262ec.js"><link rel="prefetch" href="/assets/js/144.8fcbc368.js"><link rel="prefetch" href="/assets/js/145.46da36bf.js"><link rel="prefetch" href="/assets/js/146.eceae0d9.js"><link rel="prefetch" href="/assets/js/147.e1bd6531.js"><link rel="prefetch" href="/assets/js/148.76f193ce.js"><link rel="prefetch" href="/assets/js/149.587bd581.js"><link rel="prefetch" href="/assets/js/15.e3219ac0.js"><link rel="prefetch" href="/assets/js/150.169c71e0.js"><link rel="prefetch" href="/assets/js/151.384021ea.js"><link rel="prefetch" href="/assets/js/152.0f20cf03.js"><link rel="prefetch" href="/assets/js/153.fd94af1e.js"><link rel="prefetch" href="/assets/js/154.a550f5dc.js"><link rel="prefetch" href="/assets/js/155.ba1ae86e.js"><link rel="prefetch" href="/assets/js/156.3b98ded0.js"><link rel="prefetch" href="/assets/js/157.cd378596.js"><link rel="prefetch" href="/assets/js/158.c138d0df.js"><link rel="prefetch" href="/assets/js/159.2635f7f4.js"><link rel="prefetch" href="/assets/js/16.c9c35d42.js"><link rel="prefetch" href="/assets/js/160.d51b4126.js"><link rel="prefetch" href="/assets/js/161.5dc29e7b.js"><link rel="prefetch" href="/assets/js/162.f257a92b.js"><link rel="prefetch" href="/assets/js/163.9eb75e40.js"><link rel="prefetch" href="/assets/js/164.8fb1e22b.js"><link rel="prefetch" href="/assets/js/165.49255503.js"><link rel="prefetch" href="/assets/js/166.e54539e6.js"><link rel="prefetch" href="/assets/js/167.a06acdb0.js"><link rel="prefetch" href="/assets/js/168.948ab620.js"><link rel="prefetch" href="/assets/js/169.7d756812.js"><link rel="prefetch" href="/assets/js/17.81067bc8.js"><link rel="prefetch" href="/assets/js/170.ffe63330.js"><link rel="prefetch" href="/assets/js/171.835398b9.js"><link rel="prefetch" href="/assets/js/172.3987be39.js"><link rel="prefetch" href="/assets/js/173.e3cedb8a.js"><link rel="prefetch" href="/assets/js/174.11a32588.js"><link rel="prefetch" href="/assets/js/175.da6f9782.js"><link rel="prefetch" href="/assets/js/176.50e55edc.js"><link rel="prefetch" href="/assets/js/177.a89a1d17.js"><link rel="prefetch" href="/assets/js/178.7ad3ce84.js"><link rel="prefetch" href="/assets/js/179.98a1343b.js"><link rel="prefetch" href="/assets/js/18.b67caf4c.js"><link rel="prefetch" href="/assets/js/180.4e98599b.js"><link rel="prefetch" href="/assets/js/181.dd885afd.js"><link rel="prefetch" href="/assets/js/182.789990c8.js"><link rel="prefetch" href="/assets/js/183.f11ca2fd.js"><link rel="prefetch" href="/assets/js/184.fcf128ec.js"><link rel="prefetch" href="/assets/js/185.54e1e9b6.js"><link rel="prefetch" href="/assets/js/186.db91021a.js"><link rel="prefetch" href="/assets/js/187.5309dd42.js"><link rel="prefetch" href="/assets/js/188.615821ea.js"><link rel="prefetch" href="/assets/js/189.f23f1d42.js"><link rel="prefetch" href="/assets/js/19.294a011c.js"><link rel="prefetch" href="/assets/js/190.efe894bc.js"><link rel="prefetch" href="/assets/js/191.0d14904a.js"><link rel="prefetch" href="/assets/js/192.efd25a9e.js"><link rel="prefetch" href="/assets/js/193.88151f34.js"><link rel="prefetch" href="/assets/js/194.efedce14.js"><link rel="prefetch" href="/assets/js/195.03ac15bb.js"><link rel="prefetch" href="/assets/js/196.fbc18389.js"><link rel="prefetch" href="/assets/js/197.0257ab5e.js"><link rel="prefetch" href="/assets/js/198.f1de2817.js"><link rel="prefetch" href="/assets/js/199.8f1c166b.js"><link rel="prefetch" href="/assets/js/20.1a41edb1.js"><link rel="prefetch" href="/assets/js/200.4af99727.js"><link rel="prefetch" href="/assets/js/201.9f8caef1.js"><link rel="prefetch" href="/assets/js/202.6f07d705.js"><link rel="prefetch" href="/assets/js/203.5012fe50.js"><link rel="prefetch" href="/assets/js/204.3a0dfd8e.js"><link rel="prefetch" href="/assets/js/205.0ba9b606.js"><link rel="prefetch" href="/assets/js/206.663a49ec.js"><link rel="prefetch" href="/assets/js/207.b2406149.js"><link rel="prefetch" href="/assets/js/208.b0b2dfd8.js"><link rel="prefetch" href="/assets/js/209.41a0ec9f.js"><link rel="prefetch" href="/assets/js/21.b6ea6f9a.js"><link rel="prefetch" href="/assets/js/210.6f36beb8.js"><link rel="prefetch" href="/assets/js/211.90ef6e5c.js"><link rel="prefetch" href="/assets/js/212.42339063.js"><link rel="prefetch" href="/assets/js/213.a2bfeda9.js"><link rel="prefetch" href="/assets/js/214.5c7eb42a.js"><link rel="prefetch" href="/assets/js/215.18260ae5.js"><link rel="prefetch" href="/assets/js/216.7678fd29.js"><link rel="prefetch" href="/assets/js/217.9d936f88.js"><link rel="prefetch" href="/assets/js/218.bac403c4.js"><link rel="prefetch" href="/assets/js/219.9d8cb16b.js"><link rel="prefetch" href="/assets/js/22.367cc253.js"><link rel="prefetch" href="/assets/js/220.375b7707.js"><link rel="prefetch" href="/assets/js/221.3e400da4.js"><link rel="prefetch" href="/assets/js/222.8fbd2857.js"><link rel="prefetch" href="/assets/js/223.76a10075.js"><link rel="prefetch" href="/assets/js/224.ff94cc4e.js"><link rel="prefetch" href="/assets/js/225.d4688ca6.js"><link rel="prefetch" href="/assets/js/226.b13b18af.js"><link rel="prefetch" href="/assets/js/227.288d0f96.js"><link rel="prefetch" href="/assets/js/228.60430ac0.js"><link rel="prefetch" href="/assets/js/229.da728342.js"><link rel="prefetch" href="/assets/js/23.bc3de730.js"><link rel="prefetch" href="/assets/js/230.d8417d20.js"><link rel="prefetch" href="/assets/js/231.6a9ce0b4.js"><link rel="prefetch" href="/assets/js/232.7611b413.js"><link rel="prefetch" href="/assets/js/233.94712cf9.js"><link rel="prefetch" href="/assets/js/234.93888298.js"><link rel="prefetch" href="/assets/js/235.62506981.js"><link rel="prefetch" href="/assets/js/236.5a055c7c.js"><link rel="prefetch" href="/assets/js/237.0a6c4902.js"><link rel="prefetch" href="/assets/js/238.e5f37663.js"><link rel="prefetch" href="/assets/js/239.331bba86.js"><link rel="prefetch" href="/assets/js/24.82f0901c.js"><link rel="prefetch" href="/assets/js/240.59591cfc.js"><link rel="prefetch" href="/assets/js/241.ce671f47.js"><link rel="prefetch" href="/assets/js/242.fb2542fa.js"><link rel="prefetch" href="/assets/js/243.74abc73d.js"><link rel="prefetch" href="/assets/js/244.ecd707b2.js"><link rel="prefetch" href="/assets/js/245.d728367b.js"><link rel="prefetch" href="/assets/js/246.9270e7fe.js"><link rel="prefetch" href="/assets/js/247.a421ba15.js"><link rel="prefetch" href="/assets/js/248.e759132e.js"><link rel="prefetch" href="/assets/js/249.3077fb46.js"><link rel="prefetch" href="/assets/js/25.95c551dc.js"><link rel="prefetch" href="/assets/js/250.5fe4dd03.js"><link rel="prefetch" href="/assets/js/251.4b8fe76c.js"><link rel="prefetch" href="/assets/js/252.0d1cf7ea.js"><link rel="prefetch" href="/assets/js/253.89d16ba0.js"><link rel="prefetch" href="/assets/js/254.8d1afc68.js"><link rel="prefetch" href="/assets/js/256.9defbd0e.js"><link rel="prefetch" href="/assets/js/257.1fef24fd.js"><link rel="prefetch" href="/assets/js/258.4e205286.js"><link rel="prefetch" href="/assets/js/259.f3d56efc.js"><link rel="prefetch" href="/assets/js/26.7fe56bac.js"><link rel="prefetch" href="/assets/js/260.378299e6.js"><link rel="prefetch" href="/assets/js/261.8e4fb397.js"><link rel="prefetch" href="/assets/js/262.54595d98.js"><link rel="prefetch" href="/assets/js/263.fb333dc1.js"><link rel="prefetch" href="/assets/js/264.13d13301.js"><link rel="prefetch" href="/assets/js/265.c85104bc.js"><link rel="prefetch" href="/assets/js/266.9f3d1f1c.js"><link rel="prefetch" href="/assets/js/267.fb392815.js"><link rel="prefetch" href="/assets/js/268.add7eacb.js"><link rel="prefetch" href="/assets/js/269.7e49fcc7.js"><link rel="prefetch" href="/assets/js/27.5547e5f0.js"><link rel="prefetch" href="/assets/js/270.22342070.js"><link rel="prefetch" href="/assets/js/271.59917b1a.js"><link rel="prefetch" href="/assets/js/272.4a4751d5.js"><link rel="prefetch" href="/assets/js/273.f4c2fa5c.js"><link rel="prefetch" href="/assets/js/274.1208bc94.js"><link rel="prefetch" href="/assets/js/275.f6528753.js"><link rel="prefetch" href="/assets/js/276.a68772cd.js"><link rel="prefetch" href="/assets/js/277.f154ab32.js"><link rel="prefetch" href="/assets/js/278.bb616a63.js"><link rel="prefetch" href="/assets/js/279.6a356cff.js"><link rel="prefetch" href="/assets/js/28.b08b2847.js"><link rel="prefetch" href="/assets/js/280.5afc20fc.js"><link rel="prefetch" href="/assets/js/281.3cd86225.js"><link rel="prefetch" href="/assets/js/282.3ecb92aa.js"><link rel="prefetch" href="/assets/js/283.85159ea7.js"><link rel="prefetch" href="/assets/js/284.b6545c68.js"><link rel="prefetch" href="/assets/js/285.5e83ee29.js"><link rel="prefetch" href="/assets/js/286.2aad298d.js"><link rel="prefetch" href="/assets/js/287.3ca76244.js"><link rel="prefetch" href="/assets/js/288.5b17963d.js"><link rel="prefetch" href="/assets/js/289.f47a759b.js"><link rel="prefetch" href="/assets/js/29.562dbf7d.js"><link rel="prefetch" href="/assets/js/290.36b603c7.js"><link rel="prefetch" href="/assets/js/291.a9bd8951.js"><link rel="prefetch" href="/assets/js/292.dfc54f28.js"><link rel="prefetch" href="/assets/js/293.2d061212.js"><link rel="prefetch" href="/assets/js/294.6d564a9e.js"><link rel="prefetch" href="/assets/js/295.a31dd593.js"><link rel="prefetch" href="/assets/js/296.3101e5e8.js"><link rel="prefetch" href="/assets/js/297.7efde936.js"><link rel="prefetch" href="/assets/js/298.8bb3aa68.js"><link rel="prefetch" href="/assets/js/299.8b51e6bd.js"><link rel="prefetch" href="/assets/js/3.76257eb7.js"><link rel="prefetch" href="/assets/js/30.221adea2.js"><link rel="prefetch" href="/assets/js/300.62effe45.js"><link rel="prefetch" href="/assets/js/301.98c863c5.js"><link rel="prefetch" href="/assets/js/302.e3493ab2.js"><link rel="prefetch" href="/assets/js/303.800c8028.js"><link rel="prefetch" href="/assets/js/304.b6f08986.js"><link rel="prefetch" href="/assets/js/305.09af356b.js"><link rel="prefetch" href="/assets/js/306.d0d3589d.js"><link rel="prefetch" href="/assets/js/307.ee2fd249.js"><link rel="prefetch" href="/assets/js/308.f3f76368.js"><link rel="prefetch" href="/assets/js/309.d2b5ce40.js"><link rel="prefetch" href="/assets/js/31.334fc8bb.js"><link rel="prefetch" href="/assets/js/310.b4fa2feb.js"><link rel="prefetch" href="/assets/js/311.7d747ef3.js"><link rel="prefetch" href="/assets/js/312.89bdff40.js"><link rel="prefetch" href="/assets/js/313.875b82fe.js"><link rel="prefetch" href="/assets/js/314.0bbe51c4.js"><link rel="prefetch" href="/assets/js/315.cc07dbcf.js"><link rel="prefetch" href="/assets/js/316.bc72b152.js"><link rel="prefetch" href="/assets/js/317.55462812.js"><link rel="prefetch" href="/assets/js/318.a158fda0.js"><link rel="prefetch" href="/assets/js/319.b03a5bd2.js"><link rel="prefetch" href="/assets/js/32.d6826b16.js"><link rel="prefetch" href="/assets/js/320.a5bd19b0.js"><link rel="prefetch" href="/assets/js/321.4f9faaa7.js"><link rel="prefetch" href="/assets/js/322.dbd3b4fa.js"><link rel="prefetch" href="/assets/js/323.a04e2062.js"><link rel="prefetch" href="/assets/js/324.c45b46cf.js"><link rel="prefetch" href="/assets/js/325.cd1460c4.js"><link rel="prefetch" href="/assets/js/326.bd90ef85.js"><link rel="prefetch" href="/assets/js/327.8bf38ef7.js"><link rel="prefetch" href="/assets/js/328.99e9aed3.js"><link rel="prefetch" href="/assets/js/329.de0012cb.js"><link rel="prefetch" href="/assets/js/33.b1059062.js"><link rel="prefetch" href="/assets/js/330.59f11391.js"><link rel="prefetch" href="/assets/js/331.6d16a13c.js"><link rel="prefetch" href="/assets/js/332.922ca235.js"><link rel="prefetch" href="/assets/js/333.c94c3602.js"><link rel="prefetch" href="/assets/js/334.77e02010.js"><link rel="prefetch" href="/assets/js/335.1e0c4f7b.js"><link rel="prefetch" href="/assets/js/336.5675dc4f.js"><link rel="prefetch" href="/assets/js/337.bb6e11dc.js"><link rel="prefetch" href="/assets/js/338.294981e9.js"><link rel="prefetch" href="/assets/js/339.d0376372.js"><link rel="prefetch" href="/assets/js/34.0c7d5782.js"><link rel="prefetch" href="/assets/js/340.64596428.js"><link rel="prefetch" href="/assets/js/341.ec0f9409.js"><link rel="prefetch" href="/assets/js/342.7abc47c4.js"><link rel="prefetch" href="/assets/js/343.4262d486.js"><link rel="prefetch" href="/assets/js/344.8729ad8c.js"><link rel="prefetch" href="/assets/js/345.c210d888.js"><link rel="prefetch" href="/assets/js/346.6f42f7cb.js"><link rel="prefetch" href="/assets/js/347.81b41ae5.js"><link rel="prefetch" href="/assets/js/348.07eca37c.js"><link rel="prefetch" href="/assets/js/349.8019d6f3.js"><link rel="prefetch" href="/assets/js/35.ae14e37f.js"><link rel="prefetch" href="/assets/js/350.57da2e7b.js"><link rel="prefetch" href="/assets/js/351.2e99afdf.js"><link rel="prefetch" href="/assets/js/352.67dd88b7.js"><link rel="prefetch" href="/assets/js/353.15b9f624.js"><link rel="prefetch" href="/assets/js/354.a63e8432.js"><link rel="prefetch" href="/assets/js/355.bbc16ee9.js"><link rel="prefetch" href="/assets/js/356.ff63d3bb.js"><link rel="prefetch" href="/assets/js/357.4fb2d941.js"><link rel="prefetch" href="/assets/js/358.55182977.js"><link rel="prefetch" href="/assets/js/359.265c3d26.js"><link rel="prefetch" href="/assets/js/36.b9ed4cf1.js"><link rel="prefetch" href="/assets/js/360.ced80eb3.js"><link rel="prefetch" href="/assets/js/361.afe6ba84.js"><link rel="prefetch" href="/assets/js/362.c2b62518.js"><link rel="prefetch" href="/assets/js/363.0c4a4800.js"><link rel="prefetch" href="/assets/js/364.ce60291b.js"><link rel="prefetch" href="/assets/js/365.0e3a61f9.js"><link rel="prefetch" href="/assets/js/366.d53ccb03.js"><link rel="prefetch" href="/assets/js/367.689e464d.js"><link rel="prefetch" href="/assets/js/368.418c571f.js"><link rel="prefetch" href="/assets/js/369.c2fff3c8.js"><link rel="prefetch" href="/assets/js/37.a021ac57.js"><link rel="prefetch" href="/assets/js/370.a932b958.js"><link rel="prefetch" href="/assets/js/371.7d153241.js"><link rel="prefetch" href="/assets/js/372.fb9878fa.js"><link rel="prefetch" href="/assets/js/373.85772e03.js"><link rel="prefetch" href="/assets/js/374.b4a8b1b6.js"><link rel="prefetch" href="/assets/js/375.32f70596.js"><link rel="prefetch" href="/assets/js/376.a16d79a8.js"><link rel="prefetch" href="/assets/js/377.c996b7e1.js"><link rel="prefetch" href="/assets/js/378.d37d15c7.js"><link rel="prefetch" href="/assets/js/379.b81ba7dd.js"><link rel="prefetch" href="/assets/js/38.89138658.js"><link rel="prefetch" href="/assets/js/380.524c9b31.js"><link rel="prefetch" href="/assets/js/381.7ebfd6db.js"><link rel="prefetch" href="/assets/js/382.29edda0f.js"><link rel="prefetch" href="/assets/js/383.9642a212.js"><link rel="prefetch" href="/assets/js/384.086e3b42.js"><link rel="prefetch" href="/assets/js/385.a9bb46a8.js"><link rel="prefetch" href="/assets/js/386.f2561a39.js"><link rel="prefetch" href="/assets/js/387.ba9b6aaa.js"><link rel="prefetch" href="/assets/js/388.e0ace495.js"><link rel="prefetch" href="/assets/js/389.ba8c09dd.js"><link rel="prefetch" href="/assets/js/39.04f331e3.js"><link rel="prefetch" href="/assets/js/390.de1bb48b.js"><link rel="prefetch" href="/assets/js/391.7cc6edeb.js"><link rel="prefetch" href="/assets/js/392.0493a6f7.js"><link rel="prefetch" href="/assets/js/393.ba2d3e62.js"><link rel="prefetch" href="/assets/js/394.b3aa9224.js"><link rel="prefetch" href="/assets/js/395.f4df3a60.js"><link rel="prefetch" href="/assets/js/396.09644790.js"><link rel="prefetch" href="/assets/js/397.76163964.js"><link rel="prefetch" href="/assets/js/398.377fd8fc.js"><link rel="prefetch" href="/assets/js/399.39059be5.js"><link rel="prefetch" href="/assets/js/40.a21abf05.js"><link rel="prefetch" href="/assets/js/400.559a547f.js"><link rel="prefetch" href="/assets/js/401.bc6d738c.js"><link rel="prefetch" href="/assets/js/402.c504ed7b.js"><link rel="prefetch" href="/assets/js/403.77a0af9c.js"><link rel="prefetch" href="/assets/js/404.0f408cc6.js"><link rel="prefetch" href="/assets/js/405.90b0bab6.js"><link rel="prefetch" href="/assets/js/406.01b11432.js"><link rel="prefetch" href="/assets/js/407.58991ce5.js"><link rel="prefetch" href="/assets/js/408.9806278e.js"><link rel="prefetch" href="/assets/js/409.8d9b4bb3.js"><link rel="prefetch" href="/assets/js/41.6bcfc592.js"><link rel="prefetch" href="/assets/js/410.02dee620.js"><link rel="prefetch" href="/assets/js/411.3d12d3a6.js"><link rel="prefetch" href="/assets/js/412.37a62624.js"><link rel="prefetch" href="/assets/js/413.bda7ca34.js"><link rel="prefetch" href="/assets/js/414.2abb6547.js"><link rel="prefetch" href="/assets/js/415.1d271923.js"><link rel="prefetch" href="/assets/js/416.d1b11dfe.js"><link rel="prefetch" href="/assets/js/417.fcbf07ff.js"><link rel="prefetch" href="/assets/js/418.524d40ba.js"><link rel="prefetch" href="/assets/js/419.f264e463.js"><link rel="prefetch" href="/assets/js/42.ec85a270.js"><link rel="prefetch" href="/assets/js/420.8b99e60d.js"><link rel="prefetch" href="/assets/js/421.c697d876.js"><link rel="prefetch" href="/assets/js/422.4af54ae0.js"><link rel="prefetch" href="/assets/js/423.b75f24ff.js"><link rel="prefetch" href="/assets/js/424.ea80054f.js"><link rel="prefetch" href="/assets/js/425.804b48b0.js"><link rel="prefetch" href="/assets/js/426.ffed8383.js"><link rel="prefetch" href="/assets/js/427.2040bd22.js"><link rel="prefetch" href="/assets/js/428.b878fb56.js"><link rel="prefetch" href="/assets/js/429.f81fd922.js"><link rel="prefetch" href="/assets/js/43.c174449d.js"><link rel="prefetch" href="/assets/js/430.16f328ab.js"><link rel="prefetch" href="/assets/js/431.56f11924.js"><link rel="prefetch" href="/assets/js/432.e4c77710.js"><link rel="prefetch" href="/assets/js/433.29acf14b.js"><link rel="prefetch" href="/assets/js/434.33ee22fc.js"><link rel="prefetch" href="/assets/js/435.516f7600.js"><link rel="prefetch" href="/assets/js/436.28ae526a.js"><link rel="prefetch" href="/assets/js/437.b9bac473.js"><link rel="prefetch" href="/assets/js/438.711bd934.js"><link rel="prefetch" href="/assets/js/439.fe5f28bd.js"><link rel="prefetch" href="/assets/js/44.8704338b.js"><link rel="prefetch" href="/assets/js/440.b2f48747.js"><link rel="prefetch" href="/assets/js/441.4862a724.js"><link rel="prefetch" href="/assets/js/442.751f8ae7.js"><link rel="prefetch" href="/assets/js/443.9998dbe9.js"><link rel="prefetch" href="/assets/js/444.23d3f688.js"><link rel="prefetch" href="/assets/js/445.72419f35.js"><link rel="prefetch" href="/assets/js/446.21e02b7b.js"><link rel="prefetch" href="/assets/js/447.6bd039e5.js"><link rel="prefetch" href="/assets/js/448.af29ff31.js"><link rel="prefetch" href="/assets/js/449.bbdca196.js"><link rel="prefetch" href="/assets/js/45.f8a2a3b3.js"><link rel="prefetch" href="/assets/js/450.32e470b8.js"><link rel="prefetch" href="/assets/js/451.f4c8ff6a.js"><link rel="prefetch" href="/assets/js/452.c0ec8943.js"><link rel="prefetch" href="/assets/js/453.5af475c6.js"><link rel="prefetch" href="/assets/js/454.567aa6c1.js"><link rel="prefetch" href="/assets/js/455.326072d1.js"><link rel="prefetch" href="/assets/js/456.64b88847.js"><link rel="prefetch" href="/assets/js/457.61c91559.js"><link rel="prefetch" href="/assets/js/458.4f4d43d6.js"><link rel="prefetch" href="/assets/js/459.a88891cb.js"><link rel="prefetch" href="/assets/js/46.90855a0f.js"><link rel="prefetch" href="/assets/js/460.fb9e15f6.js"><link rel="prefetch" href="/assets/js/461.998a4991.js"><link rel="prefetch" href="/assets/js/462.56ecfb03.js"><link rel="prefetch" href="/assets/js/463.582cd053.js"><link rel="prefetch" href="/assets/js/464.f12a0050.js"><link rel="prefetch" href="/assets/js/465.cc3b08a8.js"><link rel="prefetch" href="/assets/js/466.ea7e4ce2.js"><link rel="prefetch" href="/assets/js/467.58700d93.js"><link rel="prefetch" href="/assets/js/468.bb9998cd.js"><link rel="prefetch" href="/assets/js/469.232d261d.js"><link rel="prefetch" href="/assets/js/47.02516d33.js"><link rel="prefetch" href="/assets/js/470.90ab2be8.js"><link rel="prefetch" href="/assets/js/471.3652fec6.js"><link rel="prefetch" href="/assets/js/472.bc7517c9.js"><link rel="prefetch" href="/assets/js/473.27b7892f.js"><link rel="prefetch" href="/assets/js/474.0d488768.js"><link rel="prefetch" href="/assets/js/475.bc33cf17.js"><link rel="prefetch" href="/assets/js/476.76ce67eb.js"><link rel="prefetch" href="/assets/js/477.a20657f6.js"><link rel="prefetch" href="/assets/js/478.8905ef26.js"><link rel="prefetch" href="/assets/js/479.23ec3dc9.js"><link rel="prefetch" href="/assets/js/48.8d38983c.js"><link rel="prefetch" href="/assets/js/480.105bf58e.js"><link rel="prefetch" href="/assets/js/481.d62a3699.js"><link rel="prefetch" href="/assets/js/482.6cb10cdb.js"><link rel="prefetch" href="/assets/js/483.15b9ef53.js"><link rel="prefetch" href="/assets/js/484.794aff9c.js"><link rel="prefetch" href="/assets/js/485.3e6ef3cb.js"><link rel="prefetch" href="/assets/js/486.fc20eb22.js"><link rel="prefetch" href="/assets/js/487.2a4f7d47.js"><link rel="prefetch" href="/assets/js/488.24ba9af5.js"><link rel="prefetch" href="/assets/js/489.d451928e.js"><link rel="prefetch" href="/assets/js/49.bd70c59c.js"><link rel="prefetch" href="/assets/js/490.d83e4fc7.js"><link rel="prefetch" href="/assets/js/491.0210a738.js"><link rel="prefetch" href="/assets/js/492.3a69cd85.js"><link rel="prefetch" href="/assets/js/493.89d2920f.js"><link rel="prefetch" href="/assets/js/494.b7d1c15e.js"><link rel="prefetch" href="/assets/js/495.7ccfe17f.js"><link rel="prefetch" href="/assets/js/496.0d6c912a.js"><link rel="prefetch" href="/assets/js/497.087ca2c6.js"><link rel="prefetch" href="/assets/js/498.f2b3c894.js"><link rel="prefetch" href="/assets/js/499.e741f312.js"><link rel="prefetch" href="/assets/js/5.405f2620.js"><link rel="prefetch" href="/assets/js/50.9df07553.js"><link rel="prefetch" href="/assets/js/500.cb9babb9.js"><link rel="prefetch" href="/assets/js/501.63a859b6.js"><link rel="prefetch" href="/assets/js/502.f346b273.js"><link rel="prefetch" href="/assets/js/503.cdcd3de3.js"><link rel="prefetch" href="/assets/js/504.e83ec450.js"><link rel="prefetch" href="/assets/js/505.95f18293.js"><link rel="prefetch" href="/assets/js/506.02060a3c.js"><link rel="prefetch" href="/assets/js/507.859d6ae4.js"><link rel="prefetch" href="/assets/js/508.9724d886.js"><link rel="prefetch" href="/assets/js/509.e17dd53e.js"><link rel="prefetch" href="/assets/js/51.3dfc6350.js"><link rel="prefetch" href="/assets/js/510.ea0c942f.js"><link rel="prefetch" href="/assets/js/511.64a7f9a8.js"><link rel="prefetch" href="/assets/js/512.6cce418a.js"><link rel="prefetch" href="/assets/js/513.ea813fe8.js"><link rel="prefetch" href="/assets/js/514.10242470.js"><link rel="prefetch" href="/assets/js/515.5308bdf6.js"><link rel="prefetch" href="/assets/js/516.dfb113bc.js"><link rel="prefetch" href="/assets/js/517.96c71069.js"><link rel="prefetch" href="/assets/js/518.5594480e.js"><link rel="prefetch" href="/assets/js/519.91e848ae.js"><link rel="prefetch" href="/assets/js/52.dd230cd7.js"><link rel="prefetch" href="/assets/js/520.ebe69ce9.js"><link rel="prefetch" href="/assets/js/521.92b80342.js"><link rel="prefetch" href="/assets/js/522.6ce581ea.js"><link rel="prefetch" href="/assets/js/523.40b7f2f9.js"><link rel="prefetch" href="/assets/js/524.4ef256d3.js"><link rel="prefetch" href="/assets/js/525.19741e4a.js"><link rel="prefetch" href="/assets/js/526.e5de1675.js"><link rel="prefetch" href="/assets/js/527.9a79cd42.js"><link rel="prefetch" href="/assets/js/528.72732eb8.js"><link rel="prefetch" href="/assets/js/529.2ea03e45.js"><link rel="prefetch" href="/assets/js/53.a349c565.js"><link rel="prefetch" href="/assets/js/530.5d1103e7.js"><link rel="prefetch" href="/assets/js/531.82b032d6.js"><link rel="prefetch" href="/assets/js/532.12ee4beb.js"><link rel="prefetch" href="/assets/js/533.db9a90f7.js"><link rel="prefetch" href="/assets/js/534.fe139db4.js"><link rel="prefetch" href="/assets/js/535.056a6fbb.js"><link rel="prefetch" href="/assets/js/536.6bf85c15.js"><link rel="prefetch" href="/assets/js/537.6e2e1ccf.js"><link rel="prefetch" href="/assets/js/538.54eddb3b.js"><link rel="prefetch" href="/assets/js/539.6f00a207.js"><link rel="prefetch" href="/assets/js/54.e292b52f.js"><link rel="prefetch" href="/assets/js/540.9c956205.js"><link rel="prefetch" href="/assets/js/541.50f41228.js"><link rel="prefetch" href="/assets/js/542.a2b1879e.js"><link rel="prefetch" href="/assets/js/543.4e5e17c9.js"><link rel="prefetch" href="/assets/js/544.63d85227.js"><link rel="prefetch" href="/assets/js/545.c3923644.js"><link rel="prefetch" href="/assets/js/546.e64ad073.js"><link rel="prefetch" href="/assets/js/547.35a8752d.js"><link rel="prefetch" href="/assets/js/548.b62a1348.js"><link rel="prefetch" href="/assets/js/549.369e2ea0.js"><link rel="prefetch" href="/assets/js/55.21bb2983.js"><link rel="prefetch" href="/assets/js/550.b4632248.js"><link rel="prefetch" href="/assets/js/551.18f1879c.js"><link rel="prefetch" href="/assets/js/552.162e63cd.js"><link rel="prefetch" href="/assets/js/553.6998130e.js"><link rel="prefetch" href="/assets/js/554.89126c3d.js"><link rel="prefetch" href="/assets/js/555.a5f63b8a.js"><link rel="prefetch" href="/assets/js/556.35381cef.js"><link rel="prefetch" href="/assets/js/557.ceeecf52.js"><link rel="prefetch" href="/assets/js/558.253e6e4f.js"><link rel="prefetch" href="/assets/js/559.5cfbb773.js"><link rel="prefetch" href="/assets/js/56.5382d6b4.js"><link rel="prefetch" href="/assets/js/560.cca52f22.js"><link rel="prefetch" href="/assets/js/561.ea8d1141.js"><link rel="prefetch" href="/assets/js/562.c32e7b96.js"><link rel="prefetch" href="/assets/js/563.9bdd42e7.js"><link rel="prefetch" href="/assets/js/564.b3b87ec0.js"><link rel="prefetch" href="/assets/js/565.4be0d0f7.js"><link rel="prefetch" href="/assets/js/566.9f379d12.js"><link rel="prefetch" href="/assets/js/567.261e3181.js"><link rel="prefetch" href="/assets/js/568.4229e365.js"><link rel="prefetch" href="/assets/js/569.e662c167.js"><link rel="prefetch" href="/assets/js/57.8129f7e0.js"><link rel="prefetch" href="/assets/js/570.97ff6423.js"><link rel="prefetch" href="/assets/js/571.de1377cd.js"><link rel="prefetch" href="/assets/js/572.48b8400b.js"><link rel="prefetch" href="/assets/js/573.8251ebaf.js"><link rel="prefetch" href="/assets/js/574.ec3d6c1e.js"><link rel="prefetch" href="/assets/js/575.b0d429a1.js"><link rel="prefetch" href="/assets/js/576.98ce9170.js"><link rel="prefetch" href="/assets/js/577.85fc2017.js"><link rel="prefetch" href="/assets/js/578.1393ac7f.js"><link rel="prefetch" href="/assets/js/579.1340e178.js"><link rel="prefetch" href="/assets/js/58.85ac2740.js"><link rel="prefetch" href="/assets/js/580.a5979445.js"><link rel="prefetch" href="/assets/js/581.effdc269.js"><link rel="prefetch" href="/assets/js/582.13276063.js"><link rel="prefetch" href="/assets/js/583.357a2443.js"><link rel="prefetch" href="/assets/js/584.338ef731.js"><link rel="prefetch" href="/assets/js/585.87932741.js"><link rel="prefetch" href="/assets/js/586.b1d6e000.js"><link rel="prefetch" href="/assets/js/587.ed5b8377.js"><link rel="prefetch" href="/assets/js/588.16d2c418.js"><link rel="prefetch" href="/assets/js/589.c96fd7fa.js"><link rel="prefetch" href="/assets/js/59.0b225757.js"><link rel="prefetch" href="/assets/js/590.1a06b2a0.js"><link rel="prefetch" href="/assets/js/591.0efd886c.js"><link rel="prefetch" href="/assets/js/592.b22d0ef5.js"><link rel="prefetch" href="/assets/js/593.84ed6ebe.js"><link rel="prefetch" href="/assets/js/594.cd721b88.js"><link rel="prefetch" href="/assets/js/595.2400817a.js"><link rel="prefetch" href="/assets/js/596.f2c512d1.js"><link rel="prefetch" href="/assets/js/597.df10ec57.js"><link rel="prefetch" href="/assets/js/598.61ef6a7d.js"><link rel="prefetch" href="/assets/js/599.0bebb562.js"><link rel="prefetch" href="/assets/js/6.29d112b1.js"><link rel="prefetch" href="/assets/js/60.3bbab51d.js"><link rel="prefetch" href="/assets/js/600.1ea7596f.js"><link rel="prefetch" href="/assets/js/601.f2642bb3.js"><link rel="prefetch" href="/assets/js/602.400cc987.js"><link rel="prefetch" href="/assets/js/603.db77d173.js"><link rel="prefetch" href="/assets/js/604.0ffa30ae.js"><link rel="prefetch" href="/assets/js/605.32ca9607.js"><link rel="prefetch" href="/assets/js/606.8c1e5683.js"><link rel="prefetch" href="/assets/js/607.9c9463ef.js"><link rel="prefetch" href="/assets/js/608.d5efa77e.js"><link rel="prefetch" href="/assets/js/609.5bbffb7d.js"><link rel="prefetch" href="/assets/js/61.f7301486.js"><link rel="prefetch" href="/assets/js/610.5b0fc9da.js"><link rel="prefetch" href="/assets/js/611.bb8058c9.js"><link rel="prefetch" href="/assets/js/612.b0788f43.js"><link rel="prefetch" href="/assets/js/613.49511e65.js"><link rel="prefetch" href="/assets/js/614.fae3eacf.js"><link rel="prefetch" href="/assets/js/615.359e5899.js"><link rel="prefetch" href="/assets/js/616.905132f4.js"><link rel="prefetch" href="/assets/js/617.6c8c594e.js"><link rel="prefetch" href="/assets/js/618.6ac4f3ff.js"><link rel="prefetch" href="/assets/js/619.411a0c14.js"><link rel="prefetch" href="/assets/js/62.9aeede84.js"><link rel="prefetch" href="/assets/js/620.56155724.js"><link rel="prefetch" href="/assets/js/621.149d7933.js"><link rel="prefetch" href="/assets/js/622.f0c9bc08.js"><link rel="prefetch" href="/assets/js/623.e0989fbe.js"><link rel="prefetch" href="/assets/js/624.80b1f6a9.js"><link rel="prefetch" href="/assets/js/625.a0a392c4.js"><link rel="prefetch" href="/assets/js/626.56fd4e8a.js"><link rel="prefetch" href="/assets/js/627.264e7313.js"><link rel="prefetch" href="/assets/js/628.7a868b19.js"><link rel="prefetch" href="/assets/js/629.e7e15da1.js"><link rel="prefetch" href="/assets/js/63.4df55c8b.js"><link rel="prefetch" href="/assets/js/630.998c9b61.js"><link rel="prefetch" href="/assets/js/631.69aa049c.js"><link rel="prefetch" href="/assets/js/632.da3882c1.js"><link rel="prefetch" href="/assets/js/633.0d49adf0.js"><link rel="prefetch" href="/assets/js/634.f9984ede.js"><link rel="prefetch" href="/assets/js/635.f0439f65.js"><link rel="prefetch" href="/assets/js/636.54de4194.js"><link rel="prefetch" href="/assets/js/637.55d1c226.js"><link rel="prefetch" href="/assets/js/638.2a9a510f.js"><link rel="prefetch" href="/assets/js/639.8bec360e.js"><link rel="prefetch" href="/assets/js/64.7f3e5e81.js"><link rel="prefetch" href="/assets/js/640.30d7f96e.js"><link rel="prefetch" href="/assets/js/641.68100098.js"><link rel="prefetch" href="/assets/js/642.4b793817.js"><link rel="prefetch" href="/assets/js/643.d86a81ea.js"><link rel="prefetch" href="/assets/js/644.76327ea2.js"><link rel="prefetch" href="/assets/js/645.0ac6a923.js"><link rel="prefetch" href="/assets/js/646.cd92f728.js"><link rel="prefetch" href="/assets/js/647.f2c624e1.js"><link rel="prefetch" href="/assets/js/648.c8f3b955.js"><link rel="prefetch" href="/assets/js/649.6370753b.js"><link rel="prefetch" href="/assets/js/65.2beeae9b.js"><link rel="prefetch" href="/assets/js/650.afe31909.js"><link rel="prefetch" href="/assets/js/651.87971ec0.js"><link rel="prefetch" href="/assets/js/652.0adf10a6.js"><link rel="prefetch" href="/assets/js/653.1f655726.js"><link rel="prefetch" href="/assets/js/654.53e24c7c.js"><link rel="prefetch" href="/assets/js/655.c95a66ea.js"><link rel="prefetch" href="/assets/js/656.38b5a5ea.js"><link rel="prefetch" href="/assets/js/657.3167aa94.js"><link rel="prefetch" href="/assets/js/658.7c40ff62.js"><link rel="prefetch" href="/assets/js/659.5d2b9b54.js"><link rel="prefetch" href="/assets/js/66.44b214db.js"><link rel="prefetch" href="/assets/js/660.96a8da9e.js"><link rel="prefetch" href="/assets/js/661.4de3b6c1.js"><link rel="prefetch" href="/assets/js/662.7d9bf181.js"><link rel="prefetch" href="/assets/js/663.4ccaf40a.js"><link rel="prefetch" href="/assets/js/664.7ab4fa53.js"><link rel="prefetch" href="/assets/js/665.32245d26.js"><link rel="prefetch" href="/assets/js/666.e6617151.js"><link rel="prefetch" href="/assets/js/667.fb3b0547.js"><link rel="prefetch" href="/assets/js/668.3d1b2e36.js"><link rel="prefetch" href="/assets/js/669.b769905f.js"><link rel="prefetch" href="/assets/js/67.c31aaacf.js"><link rel="prefetch" href="/assets/js/670.88ed3af3.js"><link rel="prefetch" href="/assets/js/671.1aff6bfe.js"><link rel="prefetch" href="/assets/js/672.c90888f7.js"><link rel="prefetch" href="/assets/js/673.81241fdc.js"><link rel="prefetch" href="/assets/js/674.838a424d.js"><link rel="prefetch" href="/assets/js/675.603ac896.js"><link rel="prefetch" href="/assets/js/676.ff44b5dc.js"><link rel="prefetch" href="/assets/js/677.41a8087a.js"><link rel="prefetch" href="/assets/js/678.f0eb8d04.js"><link rel="prefetch" href="/assets/js/679.db78199e.js"><link rel="prefetch" href="/assets/js/68.08607c89.js"><link rel="prefetch" href="/assets/js/680.8fded9d4.js"><link rel="prefetch" href="/assets/js/681.0b019dfd.js"><link rel="prefetch" href="/assets/js/682.746e9190.js"><link rel="prefetch" href="/assets/js/683.d5c00845.js"><link rel="prefetch" href="/assets/js/684.b3207cad.js"><link rel="prefetch" href="/assets/js/685.d78f18ba.js"><link rel="prefetch" href="/assets/js/686.5aaecd19.js"><link rel="prefetch" href="/assets/js/687.821a06f4.js"><link rel="prefetch" href="/assets/js/688.8bbc1890.js"><link rel="prefetch" href="/assets/js/689.79b49e8c.js"><link rel="prefetch" href="/assets/js/69.509245d6.js"><link rel="prefetch" href="/assets/js/690.fa62f9dd.js"><link rel="prefetch" href="/assets/js/691.d3eb1a60.js"><link rel="prefetch" href="/assets/js/692.738f14bb.js"><link rel="prefetch" href="/assets/js/693.e6a497a2.js"><link rel="prefetch" href="/assets/js/694.6eea1c54.js"><link rel="prefetch" href="/assets/js/695.88e6acee.js"><link rel="prefetch" href="/assets/js/696.de10297f.js"><link rel="prefetch" href="/assets/js/697.96d04062.js"><link rel="prefetch" href="/assets/js/698.200cc84f.js"><link rel="prefetch" href="/assets/js/699.f11fc627.js"><link rel="prefetch" href="/assets/js/7.c16198b8.js"><link rel="prefetch" href="/assets/js/70.5f6285b1.js"><link rel="prefetch" href="/assets/js/700.93d48f59.js"><link rel="prefetch" href="/assets/js/701.b861f29a.js"><link rel="prefetch" href="/assets/js/702.dc82e05c.js"><link rel="prefetch" href="/assets/js/703.625ce87c.js"><link rel="prefetch" href="/assets/js/704.005a0a7c.js"><link rel="prefetch" href="/assets/js/705.16ad9230.js"><link rel="prefetch" href="/assets/js/706.4eead30a.js"><link rel="prefetch" href="/assets/js/707.730306ce.js"><link rel="prefetch" href="/assets/js/708.e37e743a.js"><link rel="prefetch" href="/assets/js/709.f2144f52.js"><link rel="prefetch" href="/assets/js/71.d5d0dae5.js"><link rel="prefetch" href="/assets/js/710.ee9d9b17.js"><link rel="prefetch" href="/assets/js/711.2813c338.js"><link rel="prefetch" href="/assets/js/712.e801bce4.js"><link rel="prefetch" href="/assets/js/713.21fc267c.js"><link rel="prefetch" href="/assets/js/714.4ec35525.js"><link rel="prefetch" href="/assets/js/715.fdc3cc84.js"><link rel="prefetch" href="/assets/js/716.324932ad.js"><link rel="prefetch" href="/assets/js/717.a072a66f.js"><link rel="prefetch" href="/assets/js/718.575e0305.js"><link rel="prefetch" href="/assets/js/719.5fdd55de.js"><link rel="prefetch" href="/assets/js/72.25648231.js"><link rel="prefetch" href="/assets/js/720.61477f23.js"><link rel="prefetch" href="/assets/js/721.c8bdab00.js"><link rel="prefetch" href="/assets/js/722.9255f385.js"><link rel="prefetch" href="/assets/js/723.f27792a4.js"><link rel="prefetch" href="/assets/js/724.cd504f88.js"><link rel="prefetch" href="/assets/js/725.55c845fa.js"><link rel="prefetch" href="/assets/js/726.bb49a9db.js"><link rel="prefetch" href="/assets/js/727.53d587fe.js"><link rel="prefetch" href="/assets/js/728.86972387.js"><link rel="prefetch" href="/assets/js/729.02fa0263.js"><link rel="prefetch" href="/assets/js/73.29902c1f.js"><link rel="prefetch" href="/assets/js/730.817156d1.js"><link rel="prefetch" href="/assets/js/731.6f5d6735.js"><link rel="prefetch" href="/assets/js/732.9a5ff781.js"><link rel="prefetch" href="/assets/js/733.bcb13916.js"><link rel="prefetch" href="/assets/js/734.11482b19.js"><link rel="prefetch" href="/assets/js/735.8c0d62f3.js"><link rel="prefetch" href="/assets/js/736.06465705.js"><link rel="prefetch" href="/assets/js/737.79741d87.js"><link rel="prefetch" href="/assets/js/738.cad12ff9.js"><link rel="prefetch" href="/assets/js/739.cb09e552.js"><link rel="prefetch" href="/assets/js/74.bcf666a0.js"><link rel="prefetch" href="/assets/js/740.029b1950.js"><link rel="prefetch" href="/assets/js/741.b937216a.js"><link rel="prefetch" href="/assets/js/742.ec02c706.js"><link rel="prefetch" href="/assets/js/743.70a96283.js"><link rel="prefetch" href="/assets/js/744.909b870c.js"><link rel="prefetch" href="/assets/js/745.80defb2d.js"><link rel="prefetch" href="/assets/js/746.fb972248.js"><link rel="prefetch" href="/assets/js/747.1a7b52fd.js"><link rel="prefetch" href="/assets/js/748.036f5d16.js"><link rel="prefetch" href="/assets/js/749.bd9a413d.js"><link rel="prefetch" href="/assets/js/75.23c5a54d.js"><link rel="prefetch" href="/assets/js/750.3f1ae8f5.js"><link rel="prefetch" href="/assets/js/751.8897bc9f.js"><link rel="prefetch" href="/assets/js/752.9b387659.js"><link rel="prefetch" href="/assets/js/753.f411ce21.js"><link rel="prefetch" href="/assets/js/754.26def684.js"><link rel="prefetch" href="/assets/js/755.923aff62.js"><link rel="prefetch" href="/assets/js/756.9965743a.js"><link rel="prefetch" href="/assets/js/757.0c6bbbfd.js"><link rel="prefetch" href="/assets/js/758.a830f8b1.js"><link rel="prefetch" href="/assets/js/759.987cad77.js"><link rel="prefetch" href="/assets/js/76.f54f3d4f.js"><link rel="prefetch" href="/assets/js/760.9f2652a0.js"><link rel="prefetch" href="/assets/js/761.df01a0ee.js"><link rel="prefetch" href="/assets/js/762.e0c05a1a.js"><link rel="prefetch" href="/assets/js/763.da8a60bd.js"><link rel="prefetch" href="/assets/js/764.9f2a2830.js"><link rel="prefetch" href="/assets/js/765.44e61161.js"><link rel="prefetch" href="/assets/js/766.cd7da8c1.js"><link rel="prefetch" href="/assets/js/767.6ea1fea2.js"><link rel="prefetch" href="/assets/js/768.91529b8f.js"><link rel="prefetch" href="/assets/js/769.194d7a3e.js"><link rel="prefetch" href="/assets/js/77.3d43a163.js"><link rel="prefetch" href="/assets/js/770.227fd5b9.js"><link rel="prefetch" href="/assets/js/771.44d5e37e.js"><link rel="prefetch" href="/assets/js/772.234d9bf6.js"><link rel="prefetch" href="/assets/js/773.ff1dfb6a.js"><link rel="prefetch" href="/assets/js/774.d401364f.js"><link rel="prefetch" href="/assets/js/775.37a7cf41.js"><link rel="prefetch" href="/assets/js/776.0cd10853.js"><link rel="prefetch" href="/assets/js/777.599a3a48.js"><link rel="prefetch" href="/assets/js/778.eef27a95.js"><link rel="prefetch" href="/assets/js/779.29351199.js"><link rel="prefetch" href="/assets/js/78.fd0780ac.js"><link rel="prefetch" href="/assets/js/780.74caed94.js"><link rel="prefetch" href="/assets/js/781.ee0fa9b5.js"><link rel="prefetch" href="/assets/js/782.7cffed09.js"><link rel="prefetch" href="/assets/js/783.7f01f518.js"><link rel="prefetch" href="/assets/js/784.5f65e3d7.js"><link rel="prefetch" href="/assets/js/785.d7e13880.js"><link rel="prefetch" href="/assets/js/786.6110d12f.js"><link rel="prefetch" href="/assets/js/787.334a5cdd.js"><link rel="prefetch" href="/assets/js/788.f261bc71.js"><link rel="prefetch" href="/assets/js/789.b6d74f7d.js"><link rel="prefetch" href="/assets/js/79.7b5d6224.js"><link rel="prefetch" href="/assets/js/790.fa948ec4.js"><link rel="prefetch" href="/assets/js/791.22080013.js"><link rel="prefetch" href="/assets/js/792.31ce806c.js"><link rel="prefetch" href="/assets/js/793.9fd0c56f.js"><link rel="prefetch" href="/assets/js/794.44a8cd9c.js"><link rel="prefetch" href="/assets/js/795.9f8346e5.js"><link rel="prefetch" href="/assets/js/796.0de9c7a1.js"><link rel="prefetch" href="/assets/js/797.83ac32a6.js"><link rel="prefetch" href="/assets/js/798.393fc81d.js"><link rel="prefetch" href="/assets/js/799.c1fb3981.js"><link rel="prefetch" href="/assets/js/8.3275ed06.js"><link rel="prefetch" href="/assets/js/80.df3f0a1f.js"><link rel="prefetch" href="/assets/js/800.2832adeb.js"><link rel="prefetch" href="/assets/js/801.04c58fc4.js"><link rel="prefetch" href="/assets/js/81.3d90ef6b.js"><link rel="prefetch" href="/assets/js/82.2d42448d.js"><link rel="prefetch" href="/assets/js/83.900b4de2.js"><link rel="prefetch" href="/assets/js/84.ff570f67.js"><link rel="prefetch" href="/assets/js/85.e3b3af39.js"><link rel="prefetch" href="/assets/js/86.17b5aedc.js"><link rel="prefetch" href="/assets/js/87.f931d1d6.js"><link rel="prefetch" href="/assets/js/88.d55863cd.js"><link rel="prefetch" href="/assets/js/89.15a9a6d7.js"><link rel="prefetch" href="/assets/js/9.04948a9d.js"><link rel="prefetch" href="/assets/js/90.22696aa9.js"><link rel="prefetch" href="/assets/js/91.f1bd8a2e.js"><link rel="prefetch" href="/assets/js/92.85733094.js"><link rel="prefetch" href="/assets/js/93.59bacfd7.js"><link rel="prefetch" href="/assets/js/94.a5f9b7a0.js"><link rel="prefetch" href="/assets/js/95.be52d65a.js"><link rel="prefetch" href="/assets/js/96.0b76ba8e.js"><link rel="prefetch" href="/assets/js/97.28183cd4.js"><link rel="prefetch" href="/assets/js/98.2d22829c.js"><link rel="prefetch" href="/assets/js/99.ed602a20.js">
    <link rel="stylesheet" href="/assets/css/0.styles.a3df589e.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">AJ</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">主页</a></div><div class="nav-item"><a href="/op/" class="nav-link">Devops</a></div><div class="nav-item"><a href="/golang/" class="nav-link">Go</a></div><div class="nav-item"><a href="/go-block/" class="nav-link">区块链</a></div><div class="nav-item"><a href="/k8s/" class="nav-link">k8s</a></div><div class="nav-item"><a href="/about.html" class="nav-link">关于我</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><span class="title">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/go-learning/" class="nav-link">go-learning</a></li><li class="dropdown-item"><!----> <a href="/post/flutter-guide/" class="nav-link">flutter</a></li><li class="dropdown-item"><!----> <a href="/mysql/" class="nav-link">mysql</a></li><li class="dropdown-item"><!----> <a href="/python/" class="nav-link">python</a></li></ul></div></div> <a href="https://github.com/ChinaArJun" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">主页</a></div><div class="nav-item"><a href="/op/" class="nav-link">Devops</a></div><div class="nav-item"><a href="/golang/" class="nav-link">Go</a></div><div class="nav-item"><a href="/go-block/" class="nav-link">区块链</a></div><div class="nav-item"><a href="/k8s/" class="nav-link">k8s</a></div><div class="nav-item"><a href="/about.html" class="nav-link">关于我</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><span class="title">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/go-learning/" class="nav-link">go-learning</a></li><li class="dropdown-item"><!----> <a href="/post/flutter-guide/" class="nav-link">flutter</a></li><li class="dropdown-item"><!----> <a href="/mysql/" class="nav-link">mysql</a></li><li class="dropdown-item"><!----> <a href="/python/" class="nav-link">python</a></li></ul></div></div> <a href="https://github.com/ChinaArJun" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav> <div></div> <div style="padding-left:1.5rem;"><div></div></div> <!----> </aside> <!----> <!----> <main class="page"><div class="theme-default-content" style="margin-bottom:-5rem;"><div class="bar"><div class="bar-intro"><div class="text">
      流逝的是岁月，不变的是情怀.
        </div> <div class="text">
      坚持学习，是为了成就更好的自己. <br></div> <div>公众号[中关村程序员]</div></div></div> <!----></div> <div class="theme-default-content content__default"><h1 align="center">《电商设计手册 | SkrShop》</h1> <p align="center">Do design No code | 只设计不码码</p> <p align="center"><img src="https://img.shields.io/badge/License-CC%20BY--NC--ND%204.0-red" alt="Lisense"></p> <p align="center"><a href="http://skrshop.tech/">skrshop.tech</a></p> <p align="center"><img width="60%" src="http://cdn.tigerb.cn/20191222164829.jpg?imageMogr2/thumbnail/1280x720!/format/webp/blur/1x0/quality/90|imageslim" style="vertical-align:middle;"></p><p></p><h1 id="版权申明"><a href="#版权申明" class="header-anchor">#</a> 版权申明</h1> <ul><li>未经版权所有者明确授权，禁止发行本手册及其被实质上修改的版本。</li> <li>未经版权所有者事先授权，禁止将此作品及其衍生作品以标准（纸质）书籍形式发行。</li></ul> <p align="center"><img width="25%" src="http://cdn.tigerb.cn/wechat-blog-qrcode.jpg?imageMogr2/thumbnail/260x260!/format/webp/blur/1x0/quality/90|imageslim" style="vertical-align:middle;"> <img width="45%" src="https://dayutalk.cn/img/pub-qr.jpeg" style="vertical-align:middle;"> <i style="display:inline-block;height:100%;vertical-align:middle;width:0;"></i></p><p></p><h1 id="star趋势"><a href="#star趋势" class="header-anchor">#</a> Star趋势</h1> <p><a href="https://starchart.cc/skr-shop/manuals" target="_blank" rel="noopener noreferrer"><img src="https://starchart.cc/skr-shop/manuals.svg" alt="Stargazers over time"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <h1 id="目录"><a href="#目录" class="header-anchor">#</a> 目录</h1> <ul><li><a href="#%E5%89%8D%E8%A8%80">前言</a></li> <li><a href="#%E6%8A%80%E6%9C%AF%E6%A0%88%E9%80%89%E5%9E%8B">技术栈选型</a></li> <li><a href="#%E4%BB%A3%E7%A0%81%E4%BB%93%E5%BA%93">代码仓库</a></li> <li><a href="#%E7%94%A8%E6%88%B7%E4%BD%93%E7%B3%BB">用户体系</a> <ul><li><a href="#%E8%B4%A6%E6%88%B7%E6%9C%8D%E5%8A%A1">账户服务</a></li> <li><a href="#%E6%9D%83%E9%99%90%E6%9C%8D%E5%8A%A1">权限服务</a></li></ul></li> <li><a href="#%E8%B4%AD%E7%89%A9%E4%BD%93%E7%B3%BB">购物体系</a> <ul><li><a href="#%E5%95%86%E5%93%81%E7%B3%BB%E7%BB%9Ftemporal%E4%B8%87%E7%89%A9">商品系统(Temporal万物)</a></li> <li><a href="#%E8%B4%AD%E7%89%A9%E8%BD%A6%E6%9C%8D%E5%8A%A1">购物车服务</a></li> <li><a href="#%E8%B4%AD%E7%89%A9%E8%BD%A6%E6%9E%B6%E6%9E%84">购物车架构</a></li></ul></li> <li><a href="#%E8%90%A5%E9%94%80%E4%BD%93%E7%B3%BB">营销体系</a> <ul><li>活动营销系统
<ul><li><a href="#%E9%80%9A%E7%94%A8%E6%8A%BD%E5%A5%96%E5%B7%A5%E5%85%B7glue%E4%B8%87%E8%83%BD%E8%83%B6">通用抽奖工具(Glue万能胶)</a></li></ul></li> <li>销售营销系统(满减/买送/加价购/限时购...)</li> <li>基础服务
<ul><li><a href="#%E7%A7%92%E6%9D%80%E6%9C%8D%E5%8A%A1">秒杀服务</a></li> <li>优惠券服务</li> <li>积分服务</li></ul></li></ul></li> <li><a href="#%E4%BA%A4%E6%98%93%E4%B8%AD%E5%BF%83">交易中心</a> <ul><li><a href="#%E5%B8%B8%E8%A7%81%E7%AC%AC%E4%B8%89%E6%96%B9%E6%94%AF%E4%BB%98%E6%B5%81%E7%A8%8B">常见第三方支付流程</a></li> <li><a href="#%E6%94%AF%E4%BB%98%E7%B3%BB%E7%BB%9F%E8%AE%BE%E8%AE%A1">支付系统设计</a></li> <li>收银台</li></ul></li> <li><a href="#%E8%AE%A2%E5%8D%95%E4%B8%AD%E5%BF%83">订单中心</a></li> <li><a href="#%E4%BB%93%E5%82%A8%E7%B3%BB%E7%BB%9F">仓储系统</a> <ul><li>地址服务</li></ul></li> <li><a href="#%E7%89%A9%E6%B5%81%E7%B3%BB%E7%BB%9F">物流系统</a></li> <li><a href="#%E5%94%AE%E5%90%8E%E6%9C%8D%E5%8A%A1">售后服务</a></li> <li><a href="#%E5%9F%BA%E7%A1%80%E6%9C%8D%E5%8A%A1">基础服务</a> <ul><li>接口静态化服务</li> <li>上传服务</li> <li>消息服务
<ul><li>短信</li> <li>邮件</li> <li>微信模板消息</li> <li>站内信</li></ul></li></ul></li></ul> <h1 id="前言"><a href="#前言" class="header-anchor">#</a> 前言</h1> <p>一直从事互联网电商开发三年多的时间了，回头想想却对整个业务流程不是很了解，说出去很是惭愧。但是身处互联网电商的环境中，或多或少接触了其中的各个业务，其次周边还有很多从事电商的同事和朋友，这都是资源。于是，我决定和我的同事、盆友们、甚至还有你们去梳理整个流程并分享出来，谈不上结果要做的多么好，至少在每一个我们有能力去做好的地方，一定会细致入微。</p> <p>除此之外，同时为了满足我们自身在工作中可能得不到的技术满足感，我们在做整个系统设计的过程中，会去使用我们最想用的技术栈。技术栈这一点我们借助docker去实现，所以最终的结果：一方面我们掌握了业务的东西，另一方面又得到了技术上的满足感，二者兼得。</p> <p>最后，出于时间的考虑，我们提出了一个想法<strong>Do design No code</strong>。<strong>【只设计不码码】</strong> 这句话的意思：最终我们设计出来整个系统的数据模型，接口文档，甚至交互过程，以及环境部署等，但是最后我们却不写代码。是吧？如果这样了写代码还有什么意义。当然，也不全是这样，出于时间的考虑当然也会用代码实现出来的，说不定最后正是对面的你去实现的。</p> <p>其次，这些内容肯定有考虑不全面或者在上规模的业务中存在更复杂的地方，欢迎指出，我们也希望学习和分享您的经验。</p> <h1 id="技术栈选型"><a href="#技术栈选型" class="header-anchor">#</a> 技术栈选型</h1> <div class="language- extra-class"><pre class="language-text"><code>- 基础环境
    + k8s
    + docker
- 存储
    + mysql
    + redis
        * codis
        * redis主从
- queue
    + kafka
    + rocketmq
    + rabbitmq
- gw
    + kong
    + zuul
- webserver
    + nginx/openresty
    + envoy
- server
    + go
    + php
- frontend
    + vue
- rpc
    + grpc
    + thrift
- 基础能力
    + 监控
        * zipkin
        * elk
        * falcon
    + 服务发现
        * zookeeper
        * etcd
    + 持续集成
        * ci/cd
- 搜索
    + es
    + solr
</code></pre></div><h1 id="代码仓库"><a href="#代码仓库" class="header-anchor">#</a> 代码仓库</h1> <p>请您耐心等待...</p> <h1 id="用户体系"><a href="#用户体系" class="header-anchor">#</a> 用户体系</h1> <p>今天，我们开始第一部分<strong>用户体系</strong>的设计。本文分为如下四大模块：</p> <ul><li>架构设计</li> <li>数据模型设计</li> <li>交互设计</li> <li>接口设计</li></ul> <h2 id="架构设计"><a href="#架构设计" class="header-anchor">#</a> 架构设计</h2> <h3 id="简单来看用户体系"><a href="#简单来看用户体系" class="header-anchor">#</a> 简单来看用户体系</h3> <p>当你第一次接触和用户相关的互联网产品时，或者曾今在我眼里。<strong>用户体系</strong>无非就是“登录”和“注册”，“修改用户信息”这些，等。简单来做的话，无非我们需要一张表去记录用户的身份信息：注册时(insert操作)，往表里插入一个数据；登录时(select&amp;update操作)，通过用户标识(手机号、邮箱等)判断用户的密码是否正确；修改用户信息(select&amp;update操作)，就是直接update这个uid的用户信息(头像、昵称等)。</p> <p align="center"><a href="http://cdn.tigerb.cn/skr-account-smaple-structure.png" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-smaple-structure.png"></a></p> <p>这样设计的确没什么问题，很简单不是么。但是随着业务的发展，一方面我们需要提供统一的用户管理(高内聚)，又要提高系统的可扩展性，所以我想呈现出来的是我理解的<strong>一个基本用户体系应该有的东西</strong>。</p> <h3 id="一个基本用户体系应该有的东西"><a href="#一个基本用户体系应该有的东西" class="header-anchor">#</a> 一个基本用户体系应该有的东西</h3> <p>首先我们对原有的用户表进行再一次的抽象(抽离用户注册、登录依赖的字段、第三方登录) -&gt; <strong>账户表</strong>，为什么这么做？随着业务的发展，以前只维护一个产品，也许某一天又开发新的产品，这样我们就可以统一的维护我们公司所有产品的注册登录逻辑，不同的产品只维护该产品和用户相关的信息即可(具体依赖产品形态)。如下图所示：</p> <p align="center"><a href="http://cdn.tigerb.cn/skr-user-system-2.png" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-user-system-2.png"></a></p> <p>上图中，还提到了第三方登录/员工表/后台权限管理，这些都是一些用户体系基本必备的结构。</p> <p>第三方登录：第三方也是登录方式的一种，我们也把它抽象到账户的一部分，如上图所示。其次，关于第三方登录这里存在一个交互方式设计存在的问题，后面交互设计时会提到。</p> <p>员工：因为上面我们抽离了账户表，所以内部的管理系统后台也可以统一的使用账户表的登录逻辑，这样全公司在账号这个事情上达到了真正的高内聚。</p> <p>提到了员工，我们的内部各种系统后台肯定涉及各种的权限管理，所以这里提到了简单的RBAC(基于角色的权限控制)，具体的逻辑数据模型设计会提到。</p> <h3 id="最终的架构"><a href="#最终的架构" class="header-anchor">#</a> 最终的架构</h3> <p>随着业务产品形态的越来越复杂，在设计架构的时候，我们需要分析其中的<strong>变与不变</strong>：</p> <ul><li>变：越来越多的产品个性化用户需求</li> <li>不变：注册登录的逻辑</li></ul> <p>最终的结果，我们把原有的用户拆成了<strong>账户</strong>和<strong>用户</strong>，同时我们也要在这里明确这两个概念的区别：</p> <ul><li>账户：整个体系唯一生产uid的地方，内聚注册登录逻辑，不涉及产品业务需求</li> <li>用户：不同产品个性化的用户需求信息</li></ul> <p>最终的架构图如下：</p> <ul><li>第一部分：账户(<strong>服务层</strong>)</li> <li>第二部分：用户(<strong>应用层</strong>，无限水平扩展)</li> <li>第三部分：员工(<strong>应用层</strong>，员工权限体系)</li></ul> <p align="center"><a href="http://cdn.tigerb.cn/skr-account-structure.jpg" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-structure.jpg"></a></p> <h2 id="数据模型设计"><a href="#数据模型设计" class="header-anchor">#</a> 数据模型设计</h2> <p>对应上面的架构，我们很容易设计出我们的数据模型(这里假设我们目前只有一个对C端的应用)：</p> <div class="language- extra-class"><pre class="language-text"><code>账户 -&gt; 1.账户表
用户 -&gt; 2.用户表
员工 -&gt; 3.员工表
</code></pre></div><p>除了上面三张表外，还需要我们的R(role)B(base)A(access)C(control)权限管理,RBAC基于角色的权限管理大家应该很熟悉，这里我就不详细说了，简单的RBAC首先需要：</p> <div class="language- extra-class"><pre class="language-text"><code>4.系统菜单表(菜单即权限)，系统的uri路径
5.权限表(菜单即权限)，具体的权限就是访问系统的菜单
6.角色表，一个角色具有哪些权限
7.员工和角色的关联表，一个员工属于哪个角色
</code></pre></div><p>好了一个简单的RBAC涉及的表基本罗列出来了，但是在我的工作经历中大家实现的权限管理往往只针对某个系统，这样对于众多的系统后台来说就是乱、重复造轮子、权限管理效率低。所以我在上面的架构设计中把权限作为了一个服务为全系统提供基础服务能力。而达到这个目的的结果我只需要再增加一张表：</p> <div class="language- extra-class"><pre class="language-text"><code>8.后台管理系统表, 登记所有的后台管理系统(这样通过系统id和系统资源uri的id就可以全局构成唯一性，单纯的uri存在重复的可能性，用uri不用url的原因是域名存在变动的可能性)
</code></pre></div><p>最后我们的用户体系应该基本就上面8张表。咦，貌似漏掉了第三方登录，我们加上吧，很简单如下：</p> <div class="language- extra-class"><pre class="language-text"><code>9. 第三方用户登录表，记录不同第三方的用户标示
</code></pre></div><p>最最后就是上面的9张表了，具体的表结构和sql如下：</p> <p align="center"><a href="http://cdn.tigerb.cn/skr-account-model.png" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-model-2.png"></a></p> <h3 id="表sql"><a href="#表sql" class="header-anchor">#</a> 表sql</h3> <p><strong>账户模型</strong></p> <div class="language-sql extra-class"><pre class="language-sql"><code>
<span class="token comment">-- 账户模型</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>account_user<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'账号id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>email<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'邮箱'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>phone<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">15</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'手机号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>username<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'用户名'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>password<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'密码'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_ip_at<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建ip'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>last_login_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'最后一次登录时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>last_login_ip_at<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'最后一次登录ip'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>login_times<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'登录次数'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_email<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>email<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_phone<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>phone<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_username<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>username<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'账户'</span><span class="token punctuation">;</span>

<span class="token comment">-- 第三方账户</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>account_platform<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>uid<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'账号id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>platform_id<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'平台id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>platform_token<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'平台access_token'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span><span class="token keyword">type</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'平台类型 0:未知,1:facebook,2:google,3:wechat,4:qq,5:weibo,6:twitter'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>nickname<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'昵称'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>avatar<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'头像'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_uid<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>uid<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_platform_id<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>platform_id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'第三方用户信息'</span><span class="token punctuation">;</span>
</code></pre></div><p><strong>用户模型</strong></p> <div class="language-sql extra-class"><pre class="language-sql"><code>
<span class="token comment">-- 用户模型</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>skr_member<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'用户id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>uid<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'账号id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>nickname<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'昵称'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>avatar<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'头像(相对路径)'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>gender<span class="token punctuation">`</span> <span class="token keyword">enum</span><span class="token punctuation">(</span><span class="token string">'male'</span><span class="token punctuation">,</span><span class="token string">'female'</span><span class="token punctuation">,</span><span class="token string">'unknow'</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'unknow'</span> <span class="token keyword">COMMENT</span> <span class="token string">'性别'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>role<span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'角色 0:普通用户 1:vip'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_uid<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>uid<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'账户信息'</span><span class="token punctuation">;</span>
</code></pre></div><p><strong>员工模型</strong></p> <div class="language-sql extra-class"><pre class="language-sql"><code>
<span class="token comment">-- 员工表</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>staff_info<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'员工id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>uid<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'账号id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>email<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'员工邮箱'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>phone<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">15</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'员工手机号'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'员工姓名'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>nickname<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'员工昵称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>avatar<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'员工头像(相对路径)'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>gender<span class="token punctuation">`</span> <span class="token keyword">enum</span><span class="token punctuation">(</span><span class="token string">'male'</span><span class="token punctuation">,</span><span class="token string">'female'</span><span class="token punctuation">,</span><span class="token string">'unknow'</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'unknow'</span> <span class="token keyword">COMMENT</span> <span class="token string">'员工性别'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_uid<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>uid<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_email<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>email<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_phone<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>phone<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'员工信息(这里列了大概的信息，多的可以垂直拆表)'</span><span class="token punctuation">;</span>

</code></pre></div><p><strong>系统权限管理模型</strong></p> <div class="language-sql extra-class"><pre class="language-sql"><code>
<span class="token comment">-- 权限管理: 系统map</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>auth_ms<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">smallint</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>ms_name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统名称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>ms_desc<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'系描述'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>ms_domain<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统域名'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_domain<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>ms_domain<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'系统map(登记目前存在的后台系统信息)'</span><span class="token punctuation">;</span>

<span class="token comment">-- 权限管理: 系统menu</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>auth_ms_menu<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>ms_id<span class="token punctuation">`</span> <span class="token keyword">smallint</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>parent_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'父菜单id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>menu_name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'菜单名称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>menu_desc<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'菜描述'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>menu_uri<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'菜单uri'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>is_show<span class="token punctuation">`</span> <span class="token keyword">enum</span><span class="token punctuation">(</span><span class="token string">'yes'</span><span class="token punctuation">,</span><span class="token string">'no'</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'no'</span> <span class="token keyword">COMMENT</span> <span class="token string">'是否展示菜单'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_ms_id<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>ms_id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_parent_id<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>parent_id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'系统menu'</span><span class="token punctuation">;</span>

<span class="token comment">-- 权限管理: 系统权限</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>auth_item<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>ms_id<span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>menu_id<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'页面/接口uri'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_ms_menu<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>ms_id<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>menu_id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'系统权限'</span><span class="token punctuation">;</span>

<span class="token comment">-- 权限管理: 系统权限(权限的各个集合)</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>auth_role<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'角色名称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">desc</span><span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'角描述'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>auth_item_set<span class="token punctuation">`</span> <span class="token keyword">text</span> <span class="token keyword">COMMENT</span> <span class="token string">'权限集合 多个值,号隔开'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'员工角色'</span><span class="token punctuation">;</span>

<span class="token comment">-- 权限管理: 角色与员工关系</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>auth_role_staff<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>staff_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'员工id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>role_set<span class="token punctuation">`</span> <span class="token keyword">text</span> <span class="token keyword">COMMENT</span> <span class="token string">'角色集合 多个值,号隔开'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span> <span class="token punctuation">`</span>idx_staff_id<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>staff_id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'权限角色与员工关系'</span><span class="token punctuation">;</span>

</code></pre></div><h2 id="交互设计"><a href="#交互设计" class="header-anchor">#</a> 交互设计</h2> <blockquote><p>友情提示：一大波图片即将到来，此处图片较多，不清楚的可点击大图查看</p></blockquote> <h3 id="注册"><a href="#注册" class="header-anchor">#</a> 注册</h3> <p>注册成功之后存在至少两种交互方式：</p> <ol><li>注册成功 -&gt; 跳转到登录页面</li> <li>注册成功 -&gt; 自动登录 -&gt; 跳转到应用首页(或者其他页面)</li></ol> <p>具体交互流程如下：</p> <p align="center"><a href="http://cdn.tigerb.cn/skr-account-register-bmpr.png" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-register-bmpr.png" width="39%"></a> <a href="http://cdn.tigerb.cn/skr-account-register.jpg" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-register.jpg" width="90%"></a> <a href="http://cdn.tigerb.cn/skr-account-register-result-2.png" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-register-result-2.png" width="90%"></a></p> <hr> <h3 id="登录"><a href="#登录" class="header-anchor">#</a> 登录</h3> <p align="center"><a href="http://cdn.tigerb.cn/skr-account-login-page.png" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-login-page.png" width="30%"></a> <a href="http://cdn.tigerb.cn/skr-account-login-logic.jpg" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-login-logic.jpg" width="90%"></a> <a href="http://cdn.tigerb.cn/skr-account-home-page.png" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-home-page.png" width="30%"></a></p> <h5 id="快捷登录"><a href="#快捷登录" class="header-anchor">#</a> 快捷登录</h5> <p>快捷登录的流程基本和上面一致只是验证密码换成了验证验证码。</p> <p align="center"><a href="http://cdn.tigerb.cn/skr-account-simple-login-page.png" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-simple-login-page.png" width="39%"></a></p> <hr> <h3 id="第三方登录"><a href="#第三方登录" class="header-anchor">#</a> 第三方登录</h3> <p>第三方登录的交互其实存在这样的问题：</p> <ol><li>第三方账户登录成功后还需要绑定手机号/Email吗？</li></ol> <p>因为我发现有些PM为了提高用户使用的简单快捷性，往往第三方登录成功后会直接产生uid，而不进行账号的绑定。这样之后在再进行账号绑定就涉及账号合并的问题，很麻烦(如果有钱包等)。如果我们一开始就进行绑定操作，这样未来账号的关系就清晰明了便于维护，第三方登录其实就相当于普通账号的别名。
最后这个事情做不做的结果就是，账户表account_user和第三方用户信息表account_platform是的<strong>一对多</strong>还是<strong>一对一</strong>的关系。</p> <ol start="2"><li>如果绑定，已经注册的手机号/Email是否可以绑定？</li></ol> <p>这个还好说，一般来说绑定的选择基本是正确的。最后具体的流程图如下：</p> <p align="center"><a href="http://cdn.tigerb.cn/skr-account-platform-login.jpg" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-platform-login.jpg" width="100%"></a></p> <p>交互界面图如下：</p> <p align="center"><a href="http://cdn.tigerb.cn/skr-account-platform-login-page.png" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-account-platform-login-page.png" width="39%"></a></p> <hr> <h3 id="后台权限管理"><a href="#后台权限管理" class="header-anchor">#</a> 后台权限管理</h3> <p>首先，我们的后台管理系统需要个响亮的称号，想了一会以前公司用过apollo,于是我准备用mars但突然冒出来个earth，地球万物之根，刚好我们这又是个全业务的基础服务管理系统，哈哈就这样吧～ <strong>Earth System</strong></p> <p><strong>Earth System</strong>的权限管理功能主要分为以下四部分：</p> <ul><li>系统管理(The manage system page)
<ul><li>编辑页面</li> <li>列表页面</li></ul></li> <li>菜单管理(The menu page)
<ul><li>编辑页面</li> <li>列表页面</li></ul></li> <li>角色管理(The role page)
<ul><li>编辑页面</li> <li>列表页面</li></ul></li> <li>员工与角色关联管理(The role staff map page)
<ul><li>编辑页面</li> <li>列表页面</li></ul></li></ul> <p>具体交互如下：</p> <p align="center"><a href="http://cdn.tigerb.cn/skr-earth-2.jpg" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-earth-2.jpg" width="100%"></a></p> <hr> <h2 id="接口设计"><a href="#接口设计" class="header-anchor">#</a> 接口设计</h2> <h3 id="应用层接口-对外"><a href="#应用层接口-对外" class="header-anchor">#</a> 应用层接口(对外)</h3> <p>1.注册接口</p> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>username</td> <td>string</td> <td>非必传</td> <td>用户账号</td></tr> <tr><td>email</td> <td>string</td> <td>email/phone两者择一</td> <td>用户邮箱</td></tr> <tr><td>phone</td> <td>string</td> <td>email/phone两者择一</td> <td>用户手机号</td></tr> <tr><td>code</td> <td>int</td> <td>必传</td> <td>验证码</td></tr></tbody></table> <p>交互方式一(跳转到登录页面)响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre></div><p>交互方式二(跳转到首页页面)响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;s_token&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户会话标示&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;s_token_expire&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户会话标示过期时间，0不过期&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;username&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户名&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;nickname&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户昵称&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;avatar&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户头像&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;gender&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户性别，male:男，female:女，other:未知&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>2.登录接口</p> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>username</td> <td>string</td> <td>username/email/phone三者择一</td> <td>用户账号</td></tr> <tr><td>email</td> <td>string</td> <td>username/email/phone三者择一</td> <td>用户邮箱</td></tr> <tr><td>phone</td> <td>string</td> <td>username/email/phone三者择一</td> <td>用户手机号</td></tr> <tr><td>password</td> <td>string</td> <td>必传</td> <td>密码</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;s_token&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户会话标示&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;s_token_expire&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户会话标示过期时间，0不过期&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;nickname&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户昵称&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;username&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户名&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;avatar&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户头像&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;gender&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户性别，male:男，female:女，other:未知&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>3.快捷登录接口</p> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>email</td> <td>string</td> <td>email/phone两者择一</td> <td>用户邮箱</td></tr> <tr><td>phone</td> <td>string</td> <td>email/phone两者择一</td> <td>用户手机号</td></tr> <tr><td>code</td> <td>int</td> <td>必传</td> <td>验证码</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;s_token&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户会话标示&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;s_token_expire&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户会话标示过期时间，0不过期&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;nickname&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户昵称&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;username&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户名&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;avatar&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户头像&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;gender&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户性别，male:男，female:女，other:未知&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>4.第三方登录接口</p> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>type</td> <td>string</td> <td>必传</td> <td>平台类型 1:facebook,2:google,3:wechat,4:qq,5:weibo,6:twitter</td></tr> <tr><td>platform_id</td> <td>string</td> <td>必传</td> <td>第三方平台用户ID</td></tr> <tr><td>platform_token</td> <td>string</td> <td>必传</td> <td>第三方平台令牌</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;s_token&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户会话标示&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;s_token_expire&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户会话标示过期时间，0不过期&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;username&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户名&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;nickname&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户昵称&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;avatar&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户头像&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;gender&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户性别，male:男，female:女，other:未知&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>5.用户信息修改接口</p> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>username</td> <td>string</td> <td>非必传</td> <td>用户账号</td></tr> <tr><td>nickname</td> <td>string</td> <td>非必传</td> <td>昵称</td></tr> <tr><td>avatar</td> <td>string</td> <td>非必传</td> <td>头像url</td></tr> <tr><td>gender</td> <td>string</td> <td>非必传</td> <td>用户性别，male:男，female:女，other:未知</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;username&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户名&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;nickname&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户昵称&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;avatar&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户头像&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;gender&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户性别，male:男，female:女，other:未知&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>6.用户登录状态校验</p> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>s_token</td> <td>string</td> <td>必传</td> <td>用户会话标示</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;s_token_expire&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户会话标示过期时间，0不过期， -1登录失效&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h3 id="服务接口-基础服务，对内"><a href="#服务接口-基础服务，对内" class="header-anchor">#</a> 服务接口(基础服务，对内)</h3> <p><strong>账户服务：</strong></p> <ol><li>注册</li></ol> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>username</td> <td>string</td> <td>非必传</td> <td>用户账号</td></tr> <tr><td>email</td> <td>string</td> <td>email/phone两者择一</td> <td>用户邮箱</td></tr> <tr><td>phone</td> <td>string</td> <td>email/phone两者择一</td> <td>用户手机号</td></tr></tbody></table> <p>交互方式一(跳转到登录页面)响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;uid&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 账户ID&quot;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><ol start="2"><li>登录</li></ol> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>username</td> <td>string</td> <td>非必传</td> <td>用户账号</td></tr> <tr><td>email</td> <td>string</td> <td>email/phone两者择一</td> <td>用户邮箱</td></tr> <tr><td>phone</td> <td>string</td> <td>email/phone两者择一</td> <td>用户手机号</td></tr> <tr><td>password</td> <td>string</td> <td>必传</td> <td>密码</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;uid&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 账户ID&quot;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><ol start="2"><li>第三方登录</li></ol> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>type</td> <td>string</td> <td>必传</td> <td>平台类型 1:facebook,2:google,3:wechat,4:qq,5:weibo,6:twitter</td></tr> <tr><td>platform_id</td> <td>string</td> <td>必传</td> <td>第三方平台用户ID</td></tr> <tr><td>platform_token</td> <td>string</td> <td>必传</td> <td>第三方平台令牌</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;uid&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 账户ID&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;nickname&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户昵称&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;avatar&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 用户头像&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p><strong>权限服务</strong></p> <ol><li>获取系统菜单</li></ol> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>ms_id</td> <td>string</td> <td>必传</td> <td>系统ID</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;ms_name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 系统名称&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;ms_desc&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 系描述&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;ms_domain&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 系统域名&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;list&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
            <span class="token punctuation">{</span>
                <span class="token property">&quot;parent_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 父菜单ID&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;menu_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 菜单ID&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;menu_name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 菜单ID&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;menu_desc&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 菜描述&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;menu_uri&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 菜单uri&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;child&quot;</span> <span class="token operator">:</span> <span class="token punctuation">[</span>
                    <span class="token punctuation">{</span>
                        <span class="token property">&quot;parent_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 父菜单ID&quot;</span><span class="token punctuation">,</span>
                        <span class="token property">&quot;menu_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 菜单ID&quot;</span><span class="token punctuation">,</span>
                        <span class="token property">&quot;menu_name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 菜单ID&quot;</span><span class="token punctuation">,</span>
                        <span class="token property">&quot;menu_desc&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 菜描述&quot;</span><span class="token punctuation">,</span>
                        <span class="token property">&quot;menu_uri&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 菜单uri&quot;</span><span class="token punctuation">,</span>
                        <span class="token property">&quot;child&quot;</span> <span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
                    <span class="token punctuation">}</span>
                <span class="token punctuation">]</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><ol start="2"><li>权限校验</li></ol> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>menu_id</td> <td>string</td> <td>必传</td> <td>菜单ID</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre></div><h1 id="购物体系"><a href="#购物体系" class="header-anchor">#</a> 购物体系</h1> <h2 id="购物车服务"><a href="#购物车服务" class="header-anchor">#</a> 购物车服务</h2> <p>对于一个电商来讲，购物车是整个购买流程最重要的一步。因为电商发展到今天购物车不仅仅只是为了完成打包下单的功能；也是收藏、对比、促销提醒、相关推荐的重要展示窗口。如此多的能力我们该如何设计保证购物车的高性能、以及良好的扩展能力来满足未来的发展呢？</p> <p>今天开始我们就以一个假定的场景来输出一个购物车设计：某某电商平台，是一个多租户模式（我们前面的诸多设计都是多租户模式），用户可以把商品加入到购物车，并切按照商户纬度来展示、排序。当然购物车也支持常规的各种操作：选择、删除、清空、商品失效等。并且有相关的促销能够提醒用户。同时为了监控、运营，要支撑购物车数据同步到监控、数仓等能力。</p> <p>本文会从用户使用的角度以及服务端两个角度来讲解系统的能力。本篇我们的主要目的是说清楚购物车的能力以及一些逻辑。下一篇会进行购物车模型设计以及接口定义。</p> <h3 id="用户视角"><a href="#用户视角" class="header-anchor">#</a> 用户视角</h3> <p>我们先来定义一下在用户侧用户操作购物车的功能有哪些？</p> <p><img src="https://dayutalk.cn/img/user-cart-c.png" alt="用户则需求"></p> <p>一个购物车基本的能力基本上都在上图中，下面我们一一来分解。</p> <h4 id="操作"><a href="#操作" class="header-anchor">#</a> 操作</h4> <p>我们从用户的角度来看，购物车对于用户来说可以添加商品到购物车（加购物车、立即购买都属于一种添加方式）；加入进购物车后，不想要了可以删除该商品（删一个、删多个、清空）；想多买可以修改购买数量，发现钱不够可以减少购买数量；或者发现红色的比白色更漂亮，可以在购物车方便的进行更换规格；对于一些价格很贵的商品，能够在购物车添加一些保障服务（其实是绑定的虚拟商品）；在要去结算的时候，还会提供选择能力让用户决定哪些商品真的本次要购买。</p> <p>通过上面的描述我们可以看到这个过程是有其内在联系的。这里说一下关于选中功能，业界有两种做法，各有优劣，我们来看一下。淘宝的产品选中状态是保存在客户端的，并且默认不选中，刷新、重新打开APP状态会消失；京东、苏宁这一类是保存在服务端，会记录用户选中状态。针对这两种情况各有优劣。</p> <p><strong>客户端：</strong></p> <ol><li>性能，选中/不选中的逻辑直接放在本地做，减少网络请求</li> <li>体验，多端不能同步，但是购物车相对来说更像是一个收藏夹，每次用户自己选择也无可厚非</li> <li>计算，价格计算时需要上传本地选中商品（也可以本地计算）</li> <li>实现，主要靠客户端实现，与服务端无关，研发解耦合</li></ol> <p><strong>服务端：</strong></p> <ol><li>性能，每次操作选中都需要调用服务端，而该操作可能很频繁，除了网络损耗，服务端也需要考虑该如何快速找到修改的商品</li> <li>体验，多端同步状态，记录历史状态</li> <li>计算，服务端可获取数据，请求时无须上传额外数据</li> <li>实现，服务端与客户端需要商定如何交互，以及返回数据（每次选中会导致价格变化），耦合在一起</li></ol> <p>个人认为这两种方式并无谁具备明显优势，完全是一种基于业务模式以及团队情况来做选择。我们这里后续的设计会基于在服务端保存商品选中状态。</p> <p>在整个操作逻辑中，有个两个比较重要的地方单独说明一下：购买方式与购物车内修改购买属性</p> <h5 id="购买方式"><a href="#购买方式" class="header-anchor">#</a> 购买方式</h5> <p>主要的购买方式有立即购买、加入购物车、拼团购三种方式。</p> <p>首先普通的加入购物车没什么太多要说的。重点来看下立即购买与拼团。</p> <p>立即购买在于操作上来说就是选择商品后直接到了订单确认页面，没有购物车中去结算这一步。但是它的实现却可以依赖购物车的逻辑来做，我们来看一下使用购物车与不使用购物车实现这个逻辑有什么差别？</p> <p>如果使用购物车来实现，也就是用户点击立即购买时，商品本质上还是加入到购物车中，但这个购物车却与原型的购物车不同，因为该购物车只能加一个商品，并且每次操作都会被覆盖。在视角效果上也是直接从商品详情页面跳转到订单确认页面。来看看这种方式的好处</p> <ol><li>与购物车在订单确认、下单逻辑上一致，内部可以直接通过购物车获取数据</li> <li>需要一个独立的专门用于一键购买的购物车来实现，内存有消耗</li></ol> <p>另外一种实现方式使用一个新的数据结构，因为一般来说一键购买更简单，它只需要商品信息、价格信息即可。每次交互均可以根据sku_id来获取。</p> <ol><li>订单确认、下单逻辑上需要进行改造，每次请求之间要传递约定参数</li> <li>节省内存，上下交互通过sku_id来保证</li></ol> <p>我们会采用使用在服务端一键购买以独立的购物车形式来实现。购物车的数据模型一致，保证了后续处理流程上的一致。</p> <p>对于拼团，他其实分为两部分，首先是开团这个动作，当团成立后。我们可以选择将成团的商品加入普通购物车，同时可以加购其它商品。也可以选择将成团商品加入一键购买的购物车，保证成团商品只能买一个。拼团模式更像是加入购物车的一个前置条件。本质上它对于购物车的设计没有影响。</p> <h5 id="购物车内修改购买属性"><a href="#购物车内修改购买属性" class="header-anchor">#</a> 购物车内修改购买属性</h5> <p>这里主要是指可以在购物车便捷的操作一些需要在spu纬度操作的事情，比如：变更规格（也就是更换sku），以及选择绑定到spu纬度的服务（保险、延保等）。</p> <p>我们重点说一下选择绑定的服务。例如：我们买一个手机，厂家提供了延保、各种其它附加服务，一般情况这种服务都是虚拟商品。但是这有个特殊情况。这些保障服务首先不能单独购买，其次他是跟主商品的数量息息相关。比如买两个手机，如果选择了加购服务，那么这些服务的数量必须是2，这会是一个联动关系。</p> <p>这些保障服务是不能进行单独购买的，它一定要跟特定的商品捆绑销售。</p> <p>服务端在存储这部分数据时一定需要考虑如何保存这种层级关系，这部分我们后面模型设计的时候大家会看到。</p> <p><img src="https://dayutalk.cn/img/product-relations.png" alt="绑定商品关系"></p> <h4 id="提醒"><a href="#提醒" class="header-anchor">#</a> 提醒</h4> <p>促销提醒很简单，返回的购物车数据，每一个商品应该携带当前的促销信息。这部分重点在于怎么获取促销信息，会在服务端看到。</p> <p>然后说下购物车数量的提醒，也就是显示当前购物车商品的数量。一般来说进入到APP就会调用一个接口，获取用户的未读消息数、购物车商品数等。这里是需要非常高的读取速度。那么这种需求该如何满足呢？</p> <p><strong>方案一：</strong> 我们可以设计一个结构保存了用户相关的这种提醒信息数量，每次直接读取这个数据即可。不需要去跟消息服务、购物车服务打交道拿这些数据。</p> <p><strong>方案二：</strong> 在消息、购物车的模型中均设计一个保存总数量的字段，在读取数据的接口中，通过并发的方式调用这些服务拿到数据后进行聚合，这样在速度上只取决于最慢的服务。</p> <p>这里我们的设计会采用 <strong>方案二</strong>，因为这样在某种程度上效率可以得到保证，同时整个系统的结构数据的一致性更容易得到保障。当然这里有个细节一定要注意，并发读取一定要设计超时，不要因为某个服务读数问题而导致拖累整个接口的性能。</p> <p>接下来再来看看促销，这部分除了提醒，还需要提供对应的入口，让用户完成促销的操作。比如说某个商品有券，那么可以直接提供入口去领取；可凑单，有入口进入凑单列表并选择商品等。这部分需要解决的问题是服务端该如何及时从商品纬度拿到这些促销活动。</p> <p>从用户的视角看完了，我们再来站在研发的角度看看服务端有哪些事情要做</p> <h3 id="研发视角"><a href="#研发视角" class="header-anchor">#</a> 研发视角</h3> <p>还是先来看看需求的汇总图：</p> <p><img src="https://dayutalk.cn/img/user-cart-s.png" alt="服务端则需求"></p> <h4 id="存储"><a href="#存储" class="header-anchor">#</a> 存储</h4> <p>对于存储，首选肯定是内存存储，至于要不要落库，我觉得没有必要。说下我的理由：</p> <ol><li>购物车的数据相对变化非常频繁，落库成本比较高，如果异步方式落库，很难保障一致性</li> <li>极端情况，cache奔溃了，仅仅需要用户重新加入购物车，并且我们可以通过cache的持久化机制来保证数据的恢复</li></ol> <p>所以对于购物车，我们只会把数据完全保存在内存中。</p> <h4 id="商品销售类型发生变化"><a href="#商品销售类型发生变化" class="header-anchor">#</a> 商品销售类型发生变化</h4> <p>现在我们来讨论 <strong>商品销售类型发生变化</strong> 这个问题。这是什么意思呢？大家想一下：比如我把A商品加入到购物车，但是一直没有结算。这时运营说针对A商品搞一个活动，拿出10个库存5折购。那么问题来了，对于之前购物车中就有该商品的用户该如何处理？<strong>这里解决的主要问题是：购物车有该商品的用户不能直接以5折买</strong>。几种方案，我们来看一下：</p> <p><strong>方案一：</strong> 促销配置后，所有购物车中有该商品的用户失效或删除，这个方案首先被pass，操作成本太高，并且用户体验差</p> <p><strong>方案二：</strong> 购物车中要区分同一个SKU，不同销售类型。也就是说在我们的购物车中不是按照SKU的纬度来加商品，而是通过 <strong>SKU+售卖类型</strong> 来生成一个唯一识别码。</p> <p>可以看到 <strong>方案二</strong> 解决了同一个sku在购物车并存的问题，并且库存之前互相不影响。不过这里又有一个问题？商品的售卖类型（或者说这个标记），该怎么什么地方设置？好像商品系统可以设计、促销系统也可以设置。我们的逻辑中会在促销系统中进行配置。因为商品属于基础逻辑，如果一改就是全局库存受到影响。活动结束后很难做到自动正常售卖。因此这个标记应该落到活动中进行设置（活动设置时会通过促销系统获取该商品之前的活动是否互斥，以确保配置的活动不会互相矛盾）。</p> <h4 id="依赖系统"><a href="#依赖系统" class="header-anchor">#</a> 依赖系统</h4> <p>购物车系统依赖了非常多的其它系统。</p> <ul><li>商品系统</li> <li>库存系统</li> <li>促销系统</li> <li>结算系统</li></ul> <p>这些依赖的系统，有的是为了传输数据，有的是为了获取数据。我们按照这两个纬度来看一下。</p> <h5 id="促销提醒与计算"><a href="#促销提醒与计算" class="header-anchor">#</a> 促销提醒与计算</h5> <p>服务端要解决的是促销的提醒与价格计算问题。</p> <p>现来说计算，针对这部分最佳的方式是，调用结算中心的价格计算。我们来看一下购物车中的价格计算与订单结算时的价格计算的差异。</p> <p>首先购物车中计算价格时不知道用户的地址，这会影响运费的计算；再是不知道用券的情况。那么其实如果解决了这两个问题，我们就可以让价格计算出自同一个逻辑，仅仅是部分入参不同罢了。因此我们这里计算时可以按照最高运费来计算，同时用券默认在购物车都不使用券。对于促销问题这里是可以通过促销系统确认选中的商品可以享受哪些价格的。因此促销的价格应该计算在内。</p> <p>接下来在再来说说如何为用户高效的提供促销的信息。先从我们的配置视野出发。</p> <p>我们在配置一个促销活动或者发一张券时，都是将多个商品归到一个促销活动或者券的下面。如果按照活动、券的纬度来获取商品效率相对比较高。</p> <p><img src="https://dayutalk.cn/img/activity-product.png" alt="活动-商品"></p> <p>但是在购物车的场景中发生了一个变化。我们是需要从商品纬度获取到该商品的所有活动信息（全平台活动、店铺活动）；
那么购物车中为了展示这些信息该怎么做？很常规的一个做法（也确实不少公司是这样）：把所有活动信息取出来，遍历出所有跟该商品相关的信息。这种做法效率很低，并且无法满足大规模的应用场景，比如双十一期间。</p> <p>因此这里为了满足该需求，促销系统需要提供一个能力按照商品获取对应促销（活动、券）。因此一般来讲促销系统配置的活动不能仅仅是按照活动纬度存储，同时还需要生成一份商品纬度的促销信息。</p> <p><img src="https://dayutalk.cn/img/product-activity.png" alt="商品-活动"></p> <h4 id="购物车数据分析"><a href="#购物车数据分析" class="header-anchor">#</a> 购物车数据分析</h4> <p>对于购物车数据来说，前端会通过埋点记录加入购物车数据的情况，但是前端埋点一般是记录触发了某个前端操作，但是并不知道该操作是否成功与否。以及无法及时了解当前整体购物车的数据情况。</p> <p>为了让运营团队更完整的了解购物车当前情况，我们通过后端打本地日志，然后通过日志收集的方式将日志同步给数据、监控等服务。</p> <h4 id="失效与排序"><a href="#失效与排序" class="header-anchor">#</a> 失效与排序</h4> <p>还有两个小部分没有讲到，一是商品该如何失效，比如：库存没有了、下架了；二是购物车中的商品是多个店铺的，排序的策略是什么？</p> <p>由于本文我们还只是讨论需求，不涉及具体的模型设计，因此只是介绍方案。首先是商品失效，这很像一个软删除操作，一旦设置，用户侧看到的商品将是无法进行结算的，只能进行删除操作。</p> <p>对于排序我们会采用的设计是：根据某个店铺在购物车中最后发生操作的时间，最新的操作肯定在最上面。</p> <h3 id="结尾"><a href="#结尾" class="header-anchor">#</a> 结尾</h3> <p>通过上面我们基本上搞清楚了购物车设计中我们要做什么，依赖的系统要提供什么能力。下篇开始进入数据模型的设计、前后端接口设计。</p> <p>如果你对购物车上面的需求还有哪些补充，欢迎留言。我们一起来完善。</p> <h2 id="购物车架构"><a href="#购物车架构" class="header-anchor">#</a> 购物车架构</h2> <p>在上一篇文章 <a href="https://dayutalk.cn/2019/12/09/%E8%B4%AD%E7%89%A9%E8%BD%A6%E8%AE%BE%E8%AE%A1%E4%B9%8B%E9%9C%80%E6%B1%82%E5%88%86%E6%9E%90/" target="_blank" rel="noopener noreferrer">购物车设计之需求分析<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a> 描述了购物车的通用需求。本文重点则在如何实现上进行架构上的设计（业务+系统架构）。</p> <h3 id="说明"><a href="#说明" class="header-anchor">#</a> 说明</h3> <p>架构设计可以分为三个层面：</p> <ul><li>业务架构</li> <li>系统架构</li> <li>技术架构</li></ul> <p>快速简单的说明下三个架构的意思；当我们拿到购物车需求时，我们说用Golang来实现，存储用Redis；这描述的是技术架构；我们对购物车代码项目进行代码分层，设计规范，以及依赖系统的规划这叫系统架构；</p> <p>那业务架构是什么呢？业务架构本质上是对系统架构的文字语言描述；什么意思？我们拿到一个需求首先要跟需求方进行沟通，建立统一的认知。比如：规范名词（购物车中说的商品与商品系统中商品的含义是不同的）；建立大家都能明白的模型，购物车、用户、商品、订单这些实体之间的互动，以及各自具备什么功能。</p> <p>在业务架构分析上有很多方法论，比如：领域驱动设计，但是它并不是唯一的业务架构分析方法，也并不是说最好的。适合你的就是最好的。我们常用的实体关系图、UML图也属于业务架构领域；</p> <p>这里需要强点一点的是，不管你用什么方式来建模设计，有设计总比没设计强，其次一定要将建模的内容体现到你的代码中去。</p> <p>本文在业务架构上的分析借助了 <code>DDD</code> （领域驱动设计）思想；还是那句话<code>适合的就是最好的</code>。</p> <h3 id="业务架构"><a href="#业务架构" class="header-anchor">#</a> 业务架构</h3> <p>通过前面的需求分析，我们已经明确我们的购物车要干什么了。先来看一下一个典型的用户操作购物车过程。</p> <p><img src="https://dayutalk.cn/img/cart-sys-00.png" alt="用户旅程"></p> <p>在这个过程中，用户使用购物车这个载体完成了商品的购买流程；不断流动的数据是商品，购物车这个载体是稳定的。这是我们系统中的稳定点与变化点。</p> <p>商品的流动方式可能多种多样，比如从不同地方加入购物车，不同方式加入购物车，生命周期在购物车中也不一样；但是这个流程是稳定的，一定是先让购物车中存在商品，然后才能去结算产生订单。</p> <p>商品在购物车中的生命周期如下：</p> <p><img src="https://dayutalk.cn/img/cart-sys-01.jpg" alt="过程"></p> <p>按照这个过程，我们来看一下每个阶段对应的操作。</p> <p><img src="https://dayutalk.cn/img/cart-sys-02.jpg" alt="过程对应的操作"></p> <p>这里注意一点，加车前这个操作其实我们可以放到购物车的添加操作中，但是由于这部分是非常不稳定且多变的。我们将其独立出来，方便后续进行扩展而不影响相对比较稳定的购物车阶段。</p> <blockquote><p>上面这三个阶段，按照DDD中的概念，应该叫做实体，他们整体构成了购物车这个域；今天我们先不讲这些概念，就先略过，后面有机会单独发文讲解。</p></blockquote> <h4 id="加车前"><a href="#加车前" class="header-anchor">#</a> 加车前</h4> <p>通过流程分析，我们总结出了系统需要具备的操作接口，以及这些接口对应的实体，现在我们先来看加车前主要要做些什么；</p> <p>加车前其实主要就是对准备加入的购物车商品进行各个纬度的校验，检查是否满足要求。</p> <p>在让用户加车前，我们首先解决的是用户从哪里卖，然后进行验证？因为同一个商品从不同渠道购买是存在不同情况的，比如：小米手机，我们是通过秒杀买，还是通过好友众筹买，或者商城直接购买，价格存在差异，但是实际上他是同一个商品；</p> <p>第二个问题是是否具备购买资格，还是上面说的，秒杀、众筹这个加车操作，不是谁都可以添加的，得现有资格。那么资格的检查也是放到这里；</p> <p>第三个问题是对这个购买的商品进行商品属性上的验证，如是否上下架，有库存，限购数量等等。</p> <p>而且大家会发现，这里的验证条件可能是非常多变的。如何构建一个方便扩展的代码呢？</p> <p><img src="https://dayutalk.cn/img/cart-sys-03.jpg" alt="加车的验证"></p> <p>整个加车过程，重要的就是根据来源来区分不同的验证。我们有两种选择方式。</p> <p>方式一：通过策略模式+门面模式的方式来搞定。策略就是根据不同的加车来源进行不同的验证，门面就是根据不同的来源封装一个个策略；</p> <p>方式二：通过责任链模式，但是这里需要有一个变化，这个链在执行过程中，可以选择跳过某些节点，比如：秒杀不需要库存、也不需要众筹的验证；</p> <p>通过综合的分析我选择了责任链的模式。贴一下核心代码</p> <div class="language- extra-class"><pre class="language-text"><code>// 每个验证逻辑要实现的接口
type Handler interface {
	Skipped(in interface{}) bool // 这里判断是否跳过
	HandleRequest(in interface{}) error // 这里进行各种验证
}

// 责任链的节点
type RequestChain struct {
	Handler
	Next *RequestChain
}

// 设置handler
func (h *RequestChain) SetNextHandler(in *RequestChain) *RequestChain {
	h.Next = in
	return in
}
</code></pre></div><p>关于设计模式，大家可以看我小伙伴的github：https://github.com/TIGERB/easy-tips/tree/master/go/src/patterns</p> <h4 id="购物车"><a href="#购物车" class="header-anchor">#</a> 购物车</h4> <p>说完了加车前，现在来看购物车这一部分。我们在之前曾讨论过，购物车可能会有多种形态的，比如：存储多个商品一起结算，某个商品立即结算等。因此购物车一定会根据渠道来进行购物车类型的选择。</p> <p>这部分的操作相对是比较稳定的。我们挑几个比较重要的操作来讲一下思路即可。</p> <h5 id="加入购物车"><a href="#加入购物车" class="header-anchor">#</a> 加入购物车</h5> <p>通过把条件验证的前置，会发现在进行加车操作时，这部分逻辑已经变得非常的轻量了。要做的主要是下面几个部分的逻辑。</p> <p><img src="https://dayutalk.cn/img/cart-sys-04.jpg" alt="加入购物车"></p> <p>这里有几个取巧的地方，首先是获取商品的逻辑，由于在前面验证的时候也会用到，因此这里前面获取后会通过参数的方式继续往后传递，因此这里不需要在读库或者调用服务来获取；</p> <p>其次这里需要把当前用户现有购物车数据获取到，然后将添加的这个商品添加进来。这是一个类似合并操作，原来这个商品是存在，相当于数量加一；需要注意这个商品跟现存的商品有没有父子关系，有没有可能加入后改变了某个活动规则，比如：原来买了2个送1个赠品，现在再添加了一个变成3个，送2个赠品；</p> <blockquote><p>注意：这里的添加并不是在购物车直接改数量，可能就是在列表、详情页直接添加添加。</p></blockquote> <p>通过将合并后的购物车数据，通过营销活动检查确认ok后，直接回写到存储中。</p> <h5 id="合并购物车"><a href="#合并购物车" class="header-anchor">#</a> 合并购物车</h5> <p>为什么会有合并购物车这个操作？因为一般电商都是准许游客身份进行操作的，因此当用户登录后需要将二者进行合并。</p> <p>这里的合并很多部分的逻辑是可以与加入购物车复用的逻辑。比如：合并后的数据都需要检查是否合法，然后覆写回存储中。因此大家可以看到这里的关联性。设计的方法在某种程度上要通用。</p> <h5 id="购物车列表"><a href="#购物车列表" class="header-anchor">#</a> 购物车列表</h5> <p>购物车列表这是一个非常重要的接口，原则上购物车接口会提供两种类型，一种简版，一种完全版本；</p> <p>简版的列表接口主要是用在类似PC首页右上角之类获取简单信息；完全版本就是在购物车列表中会用到。</p> <p>在实际实现中，购物车绝不仅仅是一个读取接口那么简单。因为我们都知道不管是商品信息、活动信息都是在不断的发生变化。因此每次的读取接口必然需要检查当前购物车中数据的合法性，然后发现不一致后需要覆写原存储的数据。</p> <p><img src="https://dayutalk.cn/img/cart-sys-05.jpg" alt="购物车列表"></p> <p>也有一些做法会在每个接口都去检查数据的合法性，我建议为了性能考虑，部分接口可以适当放宽检查，在获取列表时再进行完整的检查。比如添加接口，我只会检测我添加的商品的合法性，绝不会对整个购物车进行检查。因为该操作之后一般都会调用列表操作，那么此时还会进行校验，二者重复操作，因此只取后者。</p> <h4 id="结算"><a href="#结算" class="header-anchor">#</a> 结算</h4> <p>结算包括两部分，结算页的详情信息与提交订单。结算页可以说是在购物车列表上的一个包装，因为结算页与列表页最大的不同是需要用户选择配送地址（虚拟商品另说），此时会产生更明确的价格信息，其他基本一致。因此在设计购物车列表接口的时候，一定要考虑充分的通用性。</p> <p>这里另外一个需要注意的是：立即购买，我们也会通过结算页接口来实现，但是内部其实还是会调用添加接口，将商品添加到购物车中；有三个需要注意的地方，首先是这个添加操作是服务内部完成的，对于服务调用方是不需要感知这个加入操作的存在；其次是这个购物车在Redis中的Key是独立于普通购物车的，否则二者的商品耦合在一起非常难于操作处理；最后立即购买的购物车要考虑账号多终端登录的时候，彼此数据不能互相影响，这里可以用每个端的uuid来作为购物车的标记避免这种情况。</p> <p>购物车的最后一步是生成订单，这一步最要紧的是需要给购物车加锁，避免提交过程中数据被篡改，多说一句，很多人写的Redis分布式锁代码都存在缺陷，大家一定要注意原子性的问题，这类文章网络上很多不再赘述。</p> <p>加锁成功之后，我们这里有多种做法，一种是按照DB涉及组织数据开始写表，这适用于业务量要求不大，比如订单每秒下单量不超过2000K的；那如果你的系统并发要求非常高怎么办？</p> <p>其实也很简单，高性能的三大法宝之一：异步；我们提交的时候直接将数据快照写入MQ中，然后通过异步的方式进行消费处理，可以通过通过控制消费者的数量来提升处理能力。这种方法虽然性能提升，但是复杂度也会上升，大家需要根据自己的实际情况来选择。</p> <p>关于业务架构的设计，到此告一段落，接下来我们来看系统架构。</p> <h3 id="系统架构"><a href="#系统架构" class="header-anchor">#</a> 系统架构</h3> <p>系统结构主要包含，如何将业务架构映射过来，以及输出对应输入参数、输出参数的说明。由于输入、输出针对各自业务来确定的，而且没有什么难度，我们这里就只说如何将业务架构映射到系统架构，以及系统架构中最核心的Redis数据结构选择以及存储的数据结构设计。</p> <h4 id="代码结构"><a href="#代码结构" class="header-anchor">#</a> 代码结构</h4> <p>下面的代码目录是按照 <code>Golang</code> 来进行设计的。我们来看看如何将上面的业务架构映射到代码层面来。</p> <div class="language-golang extra-class"><pre class="language-text"><code>├── addproducts.go
├── cartlist.go
├── mergecart.go
├── entity
│   ├── cart
│   │   ├── add.go
│   │   ├── cart.go
│   │   └── list.go
│   ├── order
│   │   ├── checkout.go
│   │   ├── order.go
│   │   └── submit.go
│   └── precart
├── event
│   └── sendorder.go
├── facade
│   ├── activity.go
│   └── product.go
└── repo
</code></pre></div><p>外层有 <code>entity</code>、<code>event</code>、<code>facade</code>、<code>repo</code>这四个目录，职责如下：</p> <p><strong>entity</strong>: 存放的是我们前面分析的购物领域的三个实体；所有主要的操作都在这三个实体上；</p> <p><strong>event</strong>: 这是用来处理产生的事件，比如刚刚说的如果我们提交订单采用异步的方式，那么该目录就该完成的是如何把数据发送到MQ中去；</p> <p><strong>facade</strong>: 这儿目录是干嘛的呢？这主要是因为我们的服务还需要依赖像商品、营销活动这些服务，那么我们不应该在实体中直接调用它，因为第三方可能存在变动，或者有增加、减少，我们在这里进行以下简单的封装(设计模式中的门面模式)；</p> <p><strong>repo</strong>: 这个目录从某种程度上可以理解为 <code>Model</code>层，在整个领域服务中，如果与持久化打交道，都通过它来完成。</p> <p>最后外层的几个文件，就是我们所提供的领域服务，供应用层来进行调用的。</p> <blockquote><p>为了保证内容的紧凑，我这里放弃了对整个微服务的目录介绍，只单独介绍了领域服务，后续会单独成文介绍下微服务的整个系统架构。</p></blockquote> <p>通过上面的划分，我们完成了两件事情：</p> <ol><li><p>业务架构分析的结构在系统代码中都有映射，他们彼此体现。这样最大的好处是，保证设计与代码的一致性，看了文档你就知道对应的代码在哪里；</p></li> <li><p>每个目录各自的关注点都进行了分离，更内聚，更容易开发与维护。</p></li></ol> <h4 id="redis存储"><a href="#redis存储" class="header-anchor">#</a> Redis存储</h4> <p>现在来看，我们选择Redis作为购物商品数据的存储，我们要解决两个问题，一是我们需要存哪些数据？二是我们用什么结构来存？</p> <p>网络上很多写购物车的都是只保存一个商品id，真实场景是很难满足需求的。你想想，一个商品id如何记住用户选择的赠品？用户上次选择的活动？以及购买的商品渠道？</p> <p>综合比较通用的场景，我给出一个参考结构：</p> <div class="language-golang extra-class"><pre class="language-text"><code>// 购物车数据
type ShoppingData struct {
	Item       []*Item `json:&quot;item&quot;`
	UpdateTime int64   `json:&quot;update_time&quot;`
	Version    int32   `json:&quot;version&quot;`
}

// 单个商品item元素
type Item struct {
	ItemId       string          `json:&quot;item_id&quot;`
	ParentItemId string          `json:&quot;parent_item_id,omitempty&quot;` // 绑定的父item id
	OrderId      string          `json:&quot;order_id,omitempty&quot;`       // 绑定的订单号
	Sku          int64           `json:&quot;sku&quot;`
	Spu          int64           `json:&quot;spu&quot;`
	Channel      string          `json:&quot;channel&quot;`
	Num          int32           `json:&quot;num&quot;`
	Status       int32           `json:&quot;status&quot;`
	TTL          int32           `json:&quot;ttl&quot;`                     // 有效时间
	SalePrice    float64         `json:&quot;sale_price&quot;`              // 记录加车时候的销售价格
	SpecialPrice float64         `json:&quot;special_price,omitempty&quot;` // 指定价格加购物车
	PostFree     bool            `json:&quot;post_free,omitempty&quot;`     // 是否免邮
	Activities   []*ItemActivity `json:&quot;activities,omitempty&quot;`    // 参加的活动记录
	AddTime      int64           `json:&quot;add_time&quot;`
	UpdateTime   int64           `json:&quot;update_time&quot;`
}

// 活动
type ItemActivity struct {
	ActID    string `json:&quot;act_id&quot;`
	ActType  string `json:&quot;act_type&quot;`
	ActTitle string `json:&quot;act_title&quot;`
}
</code></pre></div><p>重点说一下 <code>Item</code> 这个结构，<code>item_id</code> 这个字段是标记购物车中某个商品的唯一标记，因为我们之前说过，同一个sku由于渠道不同，那么在购物车中会是两个不同的item；接下来的 <code>parent_item_id</code> 字段是用来标记父子关系的，这里将可能存在的树结构转成了顺序结构，我们不管是父商品还是子商品，都采用顺序存储，然后通过这个字段来进行关联；有些同学可能会奇怪，为什么会存order id这个字段呢？大家关注下自己的日常业务，比如：再来一单、定金预售等，这种一定是与某个订单相关联的，不管是为了资格验证还是数据统计。剩下的字段都是一些非常常规的字段，就不在一一介绍了；</p> <blockquote><p>字段的类型，大家根据自己的需要进行修改。</p></blockquote> <p>接下来该说怎么选择Redis的存储结构了，Redis常用的 <code>Hash Table、集合、有序集合、链表、字符串</code> 五种，我们一个个来分析。</p> <p>首先购车一定有一个key来标记这个购物车属于哪个用户的，为了简化，我们的key假设是：<code>uid:cart_type</code>。</p> <p>我们先来看如果用 <code>Hash Table</code>；我们添加时，需要用到如下命令：<code>HSET uid:cart_type sku ShoppingData</code>；看起来没问题，我们可以根据sku快速定位某个商品然后进行相关的修改等，但是注意，ShoppingData是一个json串，如果用户购物车中有非常多的商品，我们用 <code>HGETALL uid:cart_type</code> 获取到的时间复杂度是O(n)，然后代码中还需要一一反序列化，又是O(n)的复杂度。</p> <p>如果用<code>集合</code>，也会遇到类似的问题，每个购物车看做一个集合，集合中的每个元素是 ShoppingData ，取到代码中依然需要逐一反序列化(反序列化是成本)，关于有序集合与链表就不在分析，大家可以按照上面的思路去尝试下问题所在。</p> <p>看起来我们没得选，只有使用<code>String</code>，那我们来看一下<code>String</code>的契合度是什么样子。首先<code>SET uid:cart_type ShoppingDataArr</code>；我们把购物车所有的数据序列化成一个字符串存储，每次取出来的时间复杂度是O(1)，序列化、反序列化都只需要一次。看来是非常不错的选择。但是在使用中大家还是有几点需要注意。</p> <ol><li>单个Value不能太大，要不然就会出现大key问题，所以一般购物车有上限限制，比如item不能超过多少个；</li> <li>对redis的操作性能提升上来了，但是代码的就是修改单个item时的不便，必须每次读取全部然后找到对应的item进行修改；这里我们可以把从redis中的数据读取出来后，在内存中构建一个HashTable，来减少每次遍历的复杂度；</li></ol> <p>网上也看到很多Redis数据结构组合使用来保存购物车数据的，但是无疑增加了网络开销，相比起来还是String最经济划算。</p> <h3 id="总结"><a href="#总结" class="header-anchor">#</a> 总结</h3> <p>至此对于购物车的实现设计算是完结了，其中关于订单表的设计会单独放到订单模块去讲。</p> <p>对于整个购物车服务，虽然没有写的详细到某个具体的接口，但是分析到这一步，我相信大家心中都是有沟壑的，能够结合自己的业务去实现它。</p> <p>文中有些很有意思的地方，建议大家动手去做做看，有任何问题，我们随时交流。</p> <ul><li>改编版的责任链模式</li> <li>Redis的分布式事务锁实现</li></ul> <p>接下来终于要到订单部分的设计了，希望大家继续关注我们。</p> <h2 id="商品系统"><a href="#商品系统" class="header-anchor">#</a> 商品系统</h2> <h2 id="商品系统-temporal万物"><a href="#商品系统-temporal万物" class="header-anchor">#</a> 商品系统(Temporal万物)</h2> <p>今天我们开始「商品系统」的篇章。本文分为如下五大模块：</p> <ul><li>需求分析</li> <li>架构设计</li> <li>Spu和Sku的故事</li> <li>数据模型设计</li> <li>接口设计</li></ul> <p>第一篇我们主要看看一个入门的电商平台(<strong>B2C</strong>)如何去构建自己的<strong>基础商品信息</strong>，其实这个事情很简单，想想我们的现实生活，商家<strong>摆放</strong>商品到货架，客户从货架<strong>挑选</strong>商品，客户把挑选好的商品<strong>放入</strong>购物车(篮)，最后客户去收银台<strong>结账</strong>。</p> <h3 id="需求分析"><a href="#需求分析" class="header-anchor">#</a> 需求分析</h3> <p>对于一个电商平台来讲，我们怎么理解上面的简单示例呢？接着，我们来拆分上面这个简单的事情：</p> <blockquote><p>商家<strong>摆放</strong>商品到货架，客户从货架<strong>挑选</strong>商品，客户把挑选好的商品<strong>放入</strong>购物车(篮)，最后客户去收银台<strong>结账</strong></p></blockquote> <ol><li>商家是谁：电商平台</li> <li>摆放是什么意思：上架</li> <li>货架在哪：前台系统(web/app/...)</li> <li>挑选：浏览前台系统</li> <li>放入：点击前台系统「加入购物车按钮」</li> <li>...(暂不多说了)</li></ol> <p><strong>备注</strong>：本篇文章主要来看看1、2、3、4步该如何去设计。</p> <p>通过上面的分析我们可以得出下面的信息：</p> <ol><li>我们需要一个「电商平台」，电商平台里面需要有个<strong>商品后台系统</strong>。</li> <li>我们上架什么东西呢？商品！所以<strong>商品后台系统</strong>需要具备<strong>创建</strong>和<strong>发布</strong>商品到<strong>前台系统</strong>的功能。</li> <li>我们需要一个<strong>前台系统</strong>(比如网页)，前台系统具备商品列表和商品详情的页面，可供用户<strong>浏览</strong>。</li> <li>前台系统的数据怎么来？所以我们需要一个<strong>接口网关</strong>(对外统一提供服务能力，企业总线)和<strong>商品服务</strong></li></ol> <p>整理之后得到如下的需求点：</p> <table><thead><tr><th>需求点</th> <th>功能点</th> <th>项目命名</th> <th>技术栈</th></tr></thead> <tbody><tr><td>商品后台系统</td> <td>1.创建商品 2.发布商品到前台系统</td> <td>Temporal Backend</td> <td>PHP</td></tr> <tr><td>前台系统</td> <td>1.商品列表 2.商品详情</td> <td>Skr Frontend</td> <td>Vue</td></tr> <tr><td>接口网关</td> <td>企业总线</td> <td>Skr Gateway</td> <td>kong</td></tr> <tr><td>商品服务</td> <td>1.创建商品接口 2.商品状态变更接口 2.商品列表接口 3. 商品详情接口</td> <td>Temporal Service</td> <td>Golang</td></tr></tbody></table> <h3 id="架构设计-2"><a href="#架构设计-2" class="header-anchor">#</a> 架构设计</h3> <p>通过上面的需求分析，再加上之前的《电商设计手册之用户体系》中的用户体系和《支付开发，不得不了解的国内、国际第三方支付流程》中的支付服务，我们规划出以下的架构图。</p> <p align="center"><a href="http://cdn.tigerb.cn/skr-product-service.jpg" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/skr-product-service.jpg"></a></p> <h3 id="spu和sku的故事"><a href="#spu和sku的故事" class="header-anchor">#</a> Spu和Sku的故事</h3> <p>对我们程序猿来讲「商品系统」刚开始的样子就是如下三点：</p> <ol><li>创建商品功能：首先我们会有一张商品表，每创建一个商品我们会的到一个goods_id，如果商品存在父子的关系，加一个parent_id的字段就搞定了。</li> <li>商品列表接口：商品表分页查询商品。</li> <li>商品详情接口：商品表按goods_id索引查询商品信息。</li></ol> <p>很简单是吧，基本一张表就搞定了，看起来也是没什么问题的。但是呢，程序设计的巧妙之处就在于<strong>抽象能力</strong>，电商行业把<code>goods_id</code>进行了进一步的抽象，产生了Spu和Sku概念，在了解Spu和Sku定义之前，我们还得了解下<strong>销售属性</strong>的含义，举个例子便于理解：</p> <p>想想我们的现实生活，假如我们去批发市场上了一批AJ1球鞋，批发商会给我们不同<strong>配色</strong>、<strong>大小</strong>的AJ1球鞋。我们在店里销售这些商品时都会询问客户：“您是需要什么<strong>颜色</strong>和<strong>大小</strong>的AJ1球鞋呢？”。这里的<strong>颜色</strong>和<strong>大小</strong>就是所谓的<strong>销售属性</strong>，因为不同<strong>颜色</strong>和<strong>大小</strong>的AJ1球鞋可能价格不同、库存数量不同，现实生活中是不是如此，不同颜色或大小的AJ1都有差别巨大的价格。</p> <p>接着，我们来看看Spu和Sku定义：</p> <table><thead><tr><th>名称</th> <th>概念</th> <th>解释</th></tr></thead> <tbody><tr><td>Spu</td> <td>standard product unit 标准产品单位</td> <td>goods_id剥离销售属性的部分，例如：小米8。商品列表我们展示Spu列表。</td></tr> <tr><td>Sku</td> <td>stock keeping unit 库存量单位</td> <td>就是你想买的那个商品真正的编号，这个编号对应的库存就是你想买的那个商品的库存量。Spu+一或多个销售属性对应一个Sku，例如：小米8黑128G，其中黑和128G就是销售属性，小米8就是一个Spu。</td></tr></tbody></table> <p>搞清楚了么？</p> <h3 id="数据模型设计-2"><a href="#数据模型设计-2" class="header-anchor">#</a> 数据模型设计</h3> <p>所以最后简单的<strong>商品表</strong>就拆成了<strong>spu表</strong>和<strong>sku表</strong>，接着我们还抽象出来了可复用的<strong>销售属性表</strong>和<strong>销售属性值表</strong>。除此之外
我们应该还有<strong>品牌表</strong>、<strong>类别表</strong>、简单的<strong>sku库存表</strong>(目前简单设计此表，后期具体业务重构此表)。接着我们列下这些表的明细：</p> <table><thead><tr><th>表名称</th> <th>表名</th></tr></thead> <tbody><tr><td>品牌表</td> <td>product_brands</td></tr> <tr><td>类别表</td> <td>product_category</td></tr> <tr><td>spu表</td> <td>product_spu</td></tr> <tr><td>sku表</td> <td>product_sku</td></tr> <tr><td>销售属性表</td> <td>product_attr</td></tr> <tr><td>销售属性值</td> <td>product_attr_value</td></tr> <tr><td>sku库存表</td> <td>product_sku_stock</td></tr></tbody></table> <p>除了上面的表之外，我又加了另一张表 <code>关联关系冗余表 product_spu_sku_attr_map</code>，为什么呢？顾名思义，冗余用的，有了这张表，我们可以很高效的得到：</p> <ol><li>spu下 有哪些sku</li> <li>spu下 有那些销售属性</li> <li>spu下 每个销售属性对应的销售属性值(一对多)</li> <li>spu下 每个销售属性值对应的sku(一对多)</li></ol> <p>具体表结构如下所示：</p> <div class="language-sql extra-class"><pre class="language-sql"><code>
<span class="token comment">-- 品牌表 product_brands</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>product_brands<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'品牌ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'品牌名称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">desc</span><span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'品牌描述'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>logo_url<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'品牌logo图片'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'品牌表'</span><span class="token punctuation">;</span>

<span class="token comment">-- 类别表 product_category</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>product_category<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'分类ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>pid<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'父ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'分类名称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">desc</span><span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'分类描述'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>pic_url<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'分类图片'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>path<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'分类地址{pid}-{child_id}-...'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'类别表'</span><span class="token punctuation">;</span>

<span class="token comment">-- spu表 product_spu</span>
<span class="token comment">-- spu: standard product unit 标准产品单位</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>product_spu<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'SPU ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>brand_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'品牌ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>category_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'分类ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'spu名称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">desc</span><span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'spu描述'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>selling_point<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'卖点'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>unit<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'spu单位'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>banner_url<span class="token punctuation">`</span> <span class="token keyword">text</span> <span class="token keyword">COMMENT</span> <span class="token string">'banner图片 多个图片逗号分隔'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>main_url<span class="token punctuation">`</span> <span class="token keyword">text</span> <span class="token keyword">COMMENT</span> <span class="token string">'商品介绍主图 多个图片逗号分隔'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>price_fee<span class="token punctuation">`</span> <span class="token keyword">int</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'售价，整数方式保存'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>price_scale<span class="token punctuation">`</span> <span class="token keyword">tinyint</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'售价，金额对应的小数位数'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>market_price_fee<span class="token punctuation">`</span> <span class="token keyword">int</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'市场价，整数方式保存'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>market_price_scale<span class="token punctuation">`</span> <span class="token keyword">tinyint</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'市场价，金额对应的小数位数'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token operator">=</span><span class="token number">666666</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'spu表'</span><span class="token punctuation">;</span>

<span class="token comment">-- sku表 product_sku</span>
<span class="token comment">-- sku: stock keeping unit 库存量单位</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>product_sku<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'SKU ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>spu_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'SPU ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>attrs<span class="token punctuation">`</span> <span class="token keyword">text</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性值{attr_value_id}-{attr_value_id} 多个销售属性值逗号分隔'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>banner_url<span class="token punctuation">`</span> <span class="token keyword">text</span> <span class="token keyword">COMMENT</span> <span class="token string">'banner图片 多个图片逗号分隔'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>main_url<span class="token punctuation">`</span> <span class="token keyword">text</span> <span class="token keyword">COMMENT</span> <span class="token string">'商品介绍主图 多个图片逗号分隔'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>price_fee<span class="token punctuation">`</span> <span class="token keyword">int</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'售价，整数方式保存'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>price_scale<span class="token punctuation">`</span> <span class="token keyword">tinyint</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'售价，金额对应的小数位数'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>market_price_fee<span class="token punctuation">`</span> <span class="token keyword">int</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'市场价，整数方式保存'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>market_price_scale<span class="token punctuation">`</span> <span class="token keyword">tinyint</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'市场价，金额对应的小数位数'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token operator">=</span><span class="token number">666666</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'sku表'</span><span class="token punctuation">;</span>

<span class="token comment">-- 销售属性表 product_attr</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>product_attr<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性名称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">desc</span><span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性描述'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'销售属性表'</span><span class="token punctuation">;</span>

<span class="token comment">-- 销售属性值 product_attr_value</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>product_attr_value<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性值ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>attr_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">value</span><span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性值'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">desc</span><span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性值描述'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'销售属性值'</span><span class="token punctuation">;</span>

<span class="token comment">-- 关联关系冗余表 product_spu_sku_attr_map</span>
<span class="token comment">-- 1. spu下 有哪些sku</span>
<span class="token comment">-- 2. spu下 有那些销售属性</span>
<span class="token comment">-- 3. spu下 每个销售属性对应的销售属性值(一对多)</span>
<span class="token comment">-- 4. spu下 每个销售属性值对应的sku(一对多)</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>product_spu_sku_attr_map<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>spu_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'SPU ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>sku_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'SKU ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>attr_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>attr_name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性名称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>attr_value_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性值ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>attr_value_name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'销售属性值'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'关联关系冗余表'</span><span class="token punctuation">;</span>

<span class="token comment">-- sku库存表 product_sku_stock</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>product_sku_stock<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>sku_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'SKU ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>quantity<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'库存'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 1:enable, 0:disable, -1:deleted'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'sku库存表'</span><span class="token punctuation">;</span>

</code></pre></div><h3 id="接口设计-2"><a href="#接口设计-2" class="header-anchor">#</a> 接口设计</h3> <p>关于接口设计目前很简单，无非列表和详情。但是这里我做了一个很好的设计<strong>动静分离</strong>，例如库存的动态的数据，单独提供接口，其他列表和详情数据完全静态化，把流量打到CDN去，这里又会说到我们下步计划的基础服务体系里的「静态资源服务」，这个服务的主要功能就是把我们的接口数据静态化。具体的<strong>V1.0</strong>版的接口设计如下：</p> <p>1、spu详情 GET {version}/product/spu/{spu_id}</p> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>spu_id</td> <td>number</td> <td>yes</td> <td>spu ID</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;brand_info&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 品牌ID&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 品牌名称&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;desc&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 品牌描述&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;logo_url&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 品牌logo图片&quot;</span><span class="token punctuation">,</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token property">&quot;category_info&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 分类ID&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 品牌名称&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;desc&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 品牌描述&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;pic_url&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 分类图片&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;path&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 分类地址{pid}-{child_id}-...&quot;</span><span class="token punctuation">,</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token property">&quot;spu_info&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, spu id&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, spu名称&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;desc&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, spu描述&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;selling_point&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 卖点&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;unit&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, spu单位&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;banner_url&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
                <span class="token string">&quot;string, banner 图片url&quot;</span><span class="token punctuation">,</span>
                <span class="token string">&quot;string, banner 图片url&quot;</span><span class="token punctuation">,</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;main_url&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
                <span class="token string">&quot;string, 商品介绍主图 图片url&quot;</span><span class="token punctuation">,</span>
                <span class="token string">&quot;string, 商品介绍主图 图片url&quot;</span><span class="token punctuation">,</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 售价&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;market_price&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 市场价&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;attrs&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token comment">// 有那些销售属性</span>
                <span class="token punctuation">{</span>
                    <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;销售属性ID&quot;</span><span class="token punctuation">,</span>
                    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 销售属性名称&quot;</span><span class="token punctuation">,</span>
                    <span class="token property">&quot;desc&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 销售属性描述&quot;</span><span class="token punctuation">,</span>
                    <span class="token property">&quot;values&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token comment">// 每个销售属性对应的销售属性值(一对多)</span>
                        <span class="token punctuation">{</span>
                            <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;销售属性值ID&quot;</span><span class="token punctuation">,</span>
                            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 销售属性值&quot;</span><span class="token punctuation">,</span>
                            <span class="token property">&quot;desc&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 销售属性值描述&quot;</span><span class="token punctuation">,</span>
                            <span class="token comment">// 每个销售属性值对应的sku(一对多)</span>
                            <span class="token comment">// 页面初始化时，按钮不可点击逻辑判断： 如果该销售属性值下所有sku没有库存，则该销售属性按钮不可点击</span>
                            <span class="token comment">// 选择销售属性值时，按钮不可点击逻辑判断：销售属性构成双向链表，每个销售属性又是一个单向链表存改销售属性对应的所有销售属性值。每当选择一个销售属性值时先前和后一个销售属性遍历，执销售属性值下所有sku售罄的按钮不可点击，且当前销售属性值map记录key为当前点击的销售属性值ID，值统一标示一下就行，目的记录是由于选择了哪个销售属性值使得当前的销售属性值为售罄状态</span>
                            <span class="token comment">// 取消选择销售属性值时，按钮不可点击逻辑恢复判断：数据结构同上，遍历，记录的map删除key为当前取消选中的销售属性值，并判断是否还有别的key使得该销售属性值为售罄状态，如果没有则恢复未售罄状态</span>
                            <span class="token property">&quot;skus&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
                                <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
                                <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
                            <span class="token punctuation">]</span><span class="token punctuation">,</span>
                        <span class="token punctuation">}</span>
                    <span class="token punctuation">]</span><span class="token punctuation">,</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;skus&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token comment">// 有哪些sku</span>
                <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
                <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;skus_map&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                <span class="token property">&quot;{attr_value_id}-{attr_value_id}-...&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;{attr_value_id}-{attr_value_id}-...&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;{attr_value_id}-{attr_value_id}-...&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;{attr_value_id}-{attr_value_id}-...&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;{attr_value_id}-{attr_value_id}-...&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;{attr_value_id}-{attr_value_id}-...&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>2、获取spu下所有skus库存 GET {version}/stock/spu/{spu_id}</p> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>spu_id</td> <td>number</td> <td>yes</td> <td>spu ID</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;skus_stock&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                <span class="token property">&quot;int, sku id&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                    <span class="token property">&quot;quantity&quot;</span><span class="token operator">:</span> <span class="token string">&quot;int, 剩余库存数量&quot;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>3、sku详情 GET {version}/product/sku/{sku_id}</p> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>sku</td> <td>number</td> <td>yes</td> <td>sku ID</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, sku id&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, sku名称&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;desc&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, sku描述&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;unit&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, sku单位&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;banner_url&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
            <span class="token string">&quot;string, banner 图片url&quot;</span><span class="token punctuation">,</span>
            <span class="token string">&quot;string, banner 图片url&quot;</span><span class="token punctuation">,</span>
        <span class="token punctuation">]</span><span class="token punctuation">,</span>
        <span class="token property">&quot;main_url&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
            <span class="token string">&quot;string, 商品介绍主图 图片url&quot;</span><span class="token punctuation">,</span>
            <span class="token string">&quot;string, 商品介绍主图 图片url&quot;</span><span class="token punctuation">,</span>
        <span class="token punctuation">]</span><span class="token punctuation">,</span>
        <span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 售价&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;market_price&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 市场价&quot;</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>4、spu列表 GET {version}/product/spu/list</p> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>-</td> <td>-</td> <td>-</td> <td>-</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;list&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
            <span class="token punctuation">{</span>
                <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, spu id&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, spu名称&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;desc&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, spu描述&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;unit&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, spu单位&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;banner_url&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
                    <span class="token string">&quot;string, banner 图片url&quot;</span><span class="token punctuation">,</span>
                    <span class="token string">&quot;string, banner 图片url&quot;</span><span class="token punctuation">,</span>
                <span class="token punctuation">]</span><span class="token punctuation">,</span>
                <span class="token property">&quot;price&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 售价&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;market_price&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 市场价&quot;</span><span class="token punctuation">,</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h1 id="营销体系"><a href="#营销体系" class="header-anchor">#</a> 营销体系</h1> <p>营销体系在一个电商系统中承担着尖刀般的作用，为电商团队拼下无数订单，就如同现实生活中的一线销售人员，引流、促销、提高成单率和客单价。</p> <p>一个营销体系拥有各种提升GMV的手段，并且仍然在不断的推陈出新，着实令人敬佩。</p> <h2 id="营销体系拆分"><a href="#营销体系拆分" class="header-anchor">#</a> 营销体系拆分</h2> <p>按照不同的维度，我们把营销体系划分为两大系统：</p> <table><thead><tr><th>系统</th> <th>描述</th> <th>维度</th></tr></thead> <tbody><tr><td>活动营销系统</td> <td>拥有各种手段<strong>提升PV\UV</strong>，并引导消费</td> <td>PV、UV维度</td></tr> <tr><td>销售营销系统</td> <td>拥有各种<strong>降低或变相降低价格</strong>的手段，来促进消费</td> <td>价格维度</td></tr></tbody></table> <ul><li>活动营销系统：
<ul><li>抽奖
<ul><li>按时间抽奖</li> <li>按当前活动参与次数抽奖</li> <li>按数额区间抽奖</li></ul></li> <li>活动模板</li> <li>抢购？？？</li></ul></li> <li>销售营销系统：
<ul><li>满减</li> <li>满赠</li> <li>买送</li> <li>限时购(限时降价或限时折扣)</li> <li>秒杀</li> <li>加价购</li> <li>多买</li> <li>预售
<ul><li>全款预售</li> <li>定金(订金)膨胀预售</li> <li>盲售</li></ul></li> <li>拼团</li> <li>砍价</li> <li>众筹</li> <li>组合套装</li></ul></li> <li>营销体系的基础服务支撑:
<ul><li>优惠券服务
<ul><li>满减券</li> <li>折扣券</li> <li>现金券</li></ul></li> <li>积分服务</li></ul></li></ul> <h2 id="概念定义"><a href="#概念定义" class="header-anchor">#</a> 概念定义</h2> <p>营销体系中我们需要把以下概念定义清楚，要使用哪些名词，以及明确其定义，防止沟通过程中的效率低下或理解偏差：</p> <table><thead><tr><th>概念</th> <th>定义</th></tr></thead> <tbody><tr><td>抢购</td> <td>爆品/新品发售场景</td></tr> <tr><td>---</td> <td>---</td></tr> <tr><td>满减</td> <td>单笔订单满多少减多少，例如，“满500减20”</td></tr> <tr><td>满赠</td> <td>单笔订单满多少增送其他商品，例如，“满999送秋裤”</td></tr> <tr><td>买送</td> <td>买就送，例如，“全场下单送秋裤”</td></tr> <tr><td>限时购</td> <td>限定时间区间，降价或折扣</td></tr> <tr><td>秒杀</td> <td>白送价格，数量极少的销售场景，例如，“一元秒杀”</td></tr> <tr><td>加价购</td> <td>再加多少钱，可以低价购买其他推荐商品</td></tr> <tr><td>多买</td> <td>单笔订单购买多个sku，享受折扣</td></tr> <tr><td>全款预售</td> <td>预售库存一次付清</td></tr> <tr><td>订金膨胀预售</td> <td>包含订金阶段、尾款阶段，订金翻倍抵现尾款，订金可退</td></tr> <tr><td>定金膨胀预售</td> <td>包含定金阶段、尾款阶段，定金翻倍抵现尾款，定金不退</td></tr> <tr><td>盲售</td> <td>包含订金(定金)阶段，尾款阶段；不知道尾款价格，不知道sku的具体信息，只知道spu的信息（可选）</td></tr> <tr><td>拼团</td> <td>限定时间凑够多人成功支付订单(享优惠价格)</td></tr> <tr><td>砍价(点赞降价)</td> <td>限定时间邀请好友砍价到指定金额</td></tr> <tr><td>众筹</td> <td>限定时间购买人数达到指定人数及以上即可成功享受优惠价格</td></tr> <tr><td>组合套装</td> <td>多个sku捆绑销售</td></tr> <tr><td>---</td> <td>---</td></tr> <tr><td>满减券</td> <td>单笔订单满多少才能使用的优惠券</td></tr> <tr><td>折扣券</td> <td>单笔订单折扣</td></tr> <tr><td>现金券</td> <td>单笔订单抵现金</td></tr></tbody></table> <h1 id="通用抽奖工具-glue万能胶"><a href="#通用抽奖工具-glue万能胶" class="header-anchor">#</a> 通用抽奖工具(Glue万能胶)</h1> <h2 id="抽奖需求分析"><a href="#抽奖需求分析" class="header-anchor">#</a> 抽奖需求分析</h2> <p>首先我们先来回顾下<strong>营销体系</strong>的组成：</p> <table><thead><tr><th>营销体系</th></tr></thead> <tbody><tr><td>活动营销系统</td></tr> <tr><td>销售营销系统</td></tr></tbody></table> <p>今天带来的是<strong>活动营销系统</strong>下的第一个独立子系统<strong>通用抽奖工具</strong>的介绍，本篇文章主要分为如下4部分：</p> <ul><li>常见抽奖场景与归类</li> <li>抽奖需求配置</li> <li>常见奖品类型</li> <li>抽奖五要素</li></ul> <h2 id="常见抽奖场景与归类"><a href="#常见抽奖场景与归类" class="header-anchor">#</a> 常见抽奖场景与归类</h2> <p>下面是我列出来的一些常见的抽奖场景，红包雨、糖果雨、打地鼠、大转盘(九宫格)、考眼力、答题闯关、游戏闯关、支付刮刮乐、积分刮刮乐等等活动营销场景。</p> <table><thead><tr><th>活动名称</th> <th>描述</th></tr></thead> <tbody><tr><td>红包雨</td> <td>每日整点抢红包🧧抽奖，每个整点一般可参与一次</td></tr> <tr><td>糖果雨</td> <td>每日整点抢糖果🍬抽奖，每个整点一般可参与一次</td></tr> <tr><td>打地鼠</td> <td>每日整点打地鼠抽奖，每个整点一般可参与一次</td></tr> <tr><td>大转盘(九宫格)</td> <td>某个时间段，转盘抽奖，每个场一般可参N次</td></tr> <tr><td>考眼力</td> <td>某个时间段，旋转杯子猜小球在哪个被子里，猜对可抽奖，一般每日可参与N次</td></tr> <tr><td>答题闯关</td> <td>每过一关，可参与抽奖，越到后面奖品越贵重</td></tr> <tr><td>游戏闯关</td> <td>每过一关，可参与抽奖，越到后面奖品越贵重</td></tr> <tr><td>支付刮刮乐</td> <td>支付订单后可刮奖，支付金额越大奖品越贵重</td></tr> <tr><td>积分刮刮乐</td> <td>积分刮奖，消费积分额度越大奖品越贵重</td></tr></tbody></table> <p>通过上面的活动描述，我们把整个抽奖场景归为以下三类：</p> <table><thead><tr><th>类型</th> <th>活动名称</th> <th>维度</th></tr></thead> <tbody><tr><td>按时间抽奖</td> <td>红包雨、糖果雨、打地鼠、幸运大转盘(九宫格)、考眼力</td> <td>时间维度</td></tr> <tr><td>按抽奖次数抽奖</td> <td>答题闯关、游戏闯关</td> <td>参与该活动次数维度</td></tr> <tr><td>按数额范围区间抽奖</td> <td>支付刮刮乐、积分刮刮乐</td> <td>数额区间维度</td></tr></tbody></table> <p>接着我们来看下每类抽奖活动具体的抽奖需求配置。</p> <h2 id="抽奖需求配置"><a href="#抽奖需求配置" class="header-anchor">#</a> 抽奖需求配置</h2> <p>本小节每类抽奖活动的需求配置，分为如下三个部分：</p> <ul><li>活动配置</li> <li>场次配置</li> <li>奖品配置</li></ul> <h3 id="首先，第一类-按时间抽奖的需求配置"><a href="#首先，第一类-按时间抽奖的需求配置" class="header-anchor">#</a> 首先，第一类: <code>按时间抽奖</code>的需求配置</h3> <table><thead><tr><th>类型</th> <th>活动名称</th> <th>特点</th></tr></thead> <tbody><tr><td>按时间抽奖</td> <td>红包雨、糖果雨、打地鼠、幸运大转盘(九宫格)、考眼力</td> <td>时间维度</td></tr></tbody></table> <table><thead><tr><th>按时间抽奖</th> <th>是否多场次</th> <th>单场次次数限制(次)</th> <th>总场次次数限制(次)</th></tr></thead> <tbody><tr><td>红包雨</td> <td>是</td> <td>1</td> <td>N</td></tr> <tr><td>糖果雨</td> <td>是</td> <td>1</td> <td>N</td></tr> <tr><td>打地鼠</td> <td>是</td> <td>N</td> <td>N</td></tr> <tr><td>幸运大转盘(九宫格)</td> <td>否</td> <td>N</td> <td>N</td></tr> <tr><td>考眼力</td> <td>否</td> <td>N</td> <td>N</td></tr></tbody></table> <p>通过上面的分析我们得到了<strong>活动</strong>和<strong>场次</strong>的概念: 一个活动需要支持多场次的配置。</p> <ul><li>活动activity:配置活动的日期范围</li> <li>场次session:配置每场的具体时间范围</li></ul> <p><strong>红包雨的需求配置示例：</strong></p> <blockquote><p>活动特征：红包雨需要支持多场次。</p></blockquote> <p>比如双十二期间三天、每天三场整点红包雨配置如下：</p> <p>活动、场次配置：</p> <table><thead><tr><th>双十二红包雨</th></tr></thead> <tbody><tr><td>活动配置：</td></tr> <tr><td>2019-12-10 至 2019-12-12</td></tr> <tr><td>场次配置：</td></tr> <tr><td>10:00:00 至 10:01:00</td></tr> <tr><td>12:00:00 至 12:01:00</td></tr> <tr><td>18:00:00 至 18:01:00</td></tr></tbody></table> <p>奖品配置：</p> <table><thead><tr><th>场次</th> <th>奖品1</th> <th>奖品2</th> <th>---</th> <th>奖品N</th></tr></thead> <tbody><tr><td>场次10:00:00 至 10:01:00</td> <td>优惠券2元</td> <td>空奖</td> <td>---</td> <td>无</td></tr> <tr><td>场次12:00:00 至 12:01:00</td> <td>优惠券5元</td> <td>空奖</td> <td>---</td> <td>无</td></tr> <tr><td>场次18:00:00 至 18:01:00</td> <td>优惠券10元</td> <td>优惠券20元</td> <td>---</td> <td>空奖</td></tr></tbody></table> <div class="language-md extra-class"><pre class="language-md"><code>上面配置的结果如下：

2019-12-10日三场整点红包雨：
2019-12-10 10:00:00 <span class="token strike"><span class="token punctuation">~</span><span class="token content"> 10:01:00
2019-12-10 12:00:00 </span><span class="token punctuation">~</span></span> 12:01:00
2019-12-10 18:00:00 ~ 18:01:00

2019-12-11日三场整点红包雨：
2019-12-11 10:00:00 <span class="token strike"><span class="token punctuation">~</span><span class="token content"> 10:01:00
2019-12-11 12:00:00 </span><span class="token punctuation">~</span></span> 12:01:00
2019-12-11 18:00:00 ~ 18:01:00

2019-12-12日三场整点红包雨：
2019-12-12 10:00:00 <span class="token strike"><span class="token punctuation">~</span><span class="token content"> 10:01:00
2019-12-12 12:00:00 </span><span class="token punctuation">~</span></span> 12:01:00
2019-12-12 18:00:00 ~ 18:01:00
</code></pre></div><p><strong>幸运大转盘的需求配置示例：</strong></p> <blockquote><p>活动特征：幸运大转盘不需要多场次。</p></blockquote> <p>比如年货节2020-01-20 至 2020-02-10期间幸运大转盘配置如下：</p> <p>活动、场次配置：</p> <table><thead><tr><th>双十二幸运大转盘</th></tr></thead> <tbody><tr><td>活动配置：</td></tr> <tr><td>2019-12-10 至 2019-12-12</td></tr> <tr><td>场次配置：</td></tr> <tr><td>00:00:00 至 23:59:59</td></tr></tbody></table> <p>奖品配置：</p> <table><thead><tr><th>场次</th> <th>奖品1</th> <th>奖品2</th> <th>---</th> <th>奖品N</th></tr></thead> <tbody><tr><td>场次00:00:00 至 23:59:59</td> <td>优惠券2元</td> <td>空奖</td> <td>---</td> <td>无</td></tr></tbody></table> <div class="language-md extra-class"><pre class="language-md"><code>上面配置的结果如下：

幸运大转盘抽奖活动将于 2019-12-10 00:00:00 ~ 2019-12-12 23:59:59 进行
</code></pre></div><p>注意与思考：双十二幸运大转盘不需要多个场次，只配置一个场次即可，完全复用活动场次模型。</p> <h3 id="接着，第二类-按抽奖次数抽奖的需求配置"><a href="#接着，第二类-按抽奖次数抽奖的需求配置" class="header-anchor">#</a> 接着，第二类: <code>按抽奖次数抽奖</code>的需求配置</h3> <table><thead><tr><th>类型</th> <th>活动名称</th> <th>特点</th></tr></thead> <tbody><tr><td>按抽奖次数抽奖</td> <td>答题闯关、游戏闯关</td> <td>(成功参与)当前活动次数维度</td></tr></tbody></table> <p><strong>答题闯关的需求配置示例：</strong></p> <blockquote><p>活动特征：每一关的奖品不同，一般越到后面中大奖的几率越大。</p></blockquote> <p>活动、场次配置：</p> <table><thead><tr><th>双十二答题闯关</th></tr></thead> <tbody><tr><td>活动配置：</td></tr> <tr><td>2019-12-10 至 2019-12-12</td></tr> <tr><td>场次配置：</td></tr> <tr><td>00:00:00 至 23:59:59</td></tr></tbody></table> <p>奖品配置：</p> <table><thead><tr><th>双十二答题闯关</th> <th>奖品</th></tr></thead> <tbody><tr><td>第一关</td> <td>优惠券2元</td></tr> <tr><td>第二关</td> <td>优惠券5元</td></tr> <tr><td>第三关</td> <td>优惠券10元</td></tr> <tr><td>第四关</td> <td>优惠券20元</td></tr> <tr><td>第五关</td> <td>优惠券50元</td></tr> <tr><td>第六关</td> <td>优惠券100元</td></tr></tbody></table> <p>注意与思考：同理活动&amp;场次配置完全复用，同幸运大转盘配置(不需要支持多场次)。</p> <h3 id="最后，第三类-按数额范围区间抽奖的需求配置："><a href="#最后，第三类-按数额范围区间抽奖的需求配置：" class="header-anchor">#</a> 最后，第三类: <code>按数额范围区间抽奖</code>的需求配置：</h3> <table><thead><tr><th>类型</th> <th>活动名称</th> <th>特点</th></tr></thead> <tbody><tr><td>按数额范围区间抽奖</td> <td>支付刮刮乐、积分刮刮乐</td> <td>数额区间维度</td></tr></tbody></table> <p><strong>支付刮刮乐的需求配置示例：</strong></p> <blockquote><p>活动特征：不同的订单金额，一般金额越大中大奖的几率越大。</p></blockquote> <p>活动、场次配置:</p> <table><thead><tr><th>双十二答题闯关</th></tr></thead> <tbody><tr><td>活动配置：</td></tr> <tr><td>2019-12-10 至 2019-12-12</td></tr> <tr><td>场次配置：</td></tr> <tr><td>00:00:00 至 23:59:59</td></tr></tbody></table> <p>奖品配置：</p> <table><thead><tr><th>订单金额</th> <th>奖品1</th> <th>奖品2</th> <th>---</th> <th>奖品N</th></tr></thead> <tbody><tr><td>0~100</td> <td>优惠券2元</td> <td>空奖</td> <td>---</td> <td>无</td></tr> <tr><td>100~200</td> <td>优惠券5元</td> <td>空奖</td> <td>---</td> <td>无</td></tr> <tr><td>200~1000</td> <td>优惠券10元</td> <td>优惠券20元</td> <td>---</td> <td>空奖</td></tr> <tr><td>1000以上</td> <td>优惠券50元</td> <td>笔记本电脑</td> <td>---</td> <td>空奖</td></tr></tbody></table> <p>注意与思考：同理活动&amp;场次配置完全复用，同幸运大转盘配置(不需要支持多场次)。</p> <blockquote><p>总结: 通过上面的分析我们得到了抽奖工具的两个要素<strong>活动</strong>和<strong>场次</strong>。</p></blockquote> <h2 id="常见奖品类型"><a href="#常见奖品类型" class="header-anchor">#</a> 常见奖品类型</h2> <blockquote><p>抽奖抽什么？</p></blockquote> <table><thead><tr><th>常见奖品类型</th></tr></thead> <tbody><tr><td>优惠券</td></tr> <tr><td>积分</td></tr> <tr><td>实物</td></tr> <tr><td>空奖</td></tr></tbody></table> <blockquote><p>总结: 我们得到了抽奖工具的另一个要素<strong>奖品</strong>。</p></blockquote> <h2 id="抽奖五要素"><a href="#抽奖五要素" class="header-anchor">#</a> 抽奖五要素</h2> <p>通过上面的分析我们已经得到了抽奖的<strong>三要素</strong></p> <ul><li>活动</li> <li>场次</li> <li>奖品</li></ul> <blockquote><p>那还有什么要素我们还没聊到呢？接下来来看。</p></blockquote> <h4 id="第四要素：中奖概率"><a href="#第四要素：中奖概率" class="header-anchor">#</a> 第四要素：中奖概率</h4> <p>抽奖自然离不开奖品的中奖概率的设置。关于中奖概率我们支持如下灵活的配置：</p> <ol><li>手动设置奖品中奖概率</li> <li>自动概率，根据当前奖品的数量、奖品的权重得到中奖概率</li></ol> <p>比如我们某次大促活动红包雨的配置如下：</p> <table><thead><tr><th>活动配置</th> <th>描述</th></tr></thead> <tbody><tr><td>活动时间</td> <td>2019-12-10至2019-12-12</td></tr> <tr><td>活动名称</td> <td>2019双十二大促整点红包雨</td></tr> <tr><td>活动描述</td> <td>2019双十二大促全端整点红包雨活动</td></tr> <tr><td>手动设置奖品概率</td> <td>是</td></tr></tbody></table> <table><thead><tr><th>场次</th> <th>奖品类型</th> <th>具体奖品</th> <th>奖品数量</th> <th>中奖概率</th></tr></thead> <tbody><tr><td>10:00:00 ~ 10:01:00</td> <td>优惠券</td> <td>2元优惠券</td> <td>2000</td> <td>50%</td></tr> <tr><td>-</td> <td>优惠券</td> <td>5元优惠券</td> <td>1000</td> <td>20%</td></tr> <tr><td>-</td> <td>空奖</td> <td>-</td> <td>5000</td> <td>30%</td></tr> <tr><td>12:00:00 ~ 12:01:00</td> <td>优惠券</td> <td>2元优惠券</td> <td>2000</td> <td>50%</td></tr> <tr><td>-</td> <td>优惠券</td> <td>5元优惠券</td> <td>1000</td> <td>20%</td></tr> <tr><td>-</td> <td>空奖</td> <td>-</td> <td>5000</td> <td>30%</td></tr> <tr><td>18:00:00 ~ 18:01:00</td> <td>优惠券</td> <td>2元优惠券</td> <td>2000</td> <td>50%</td></tr> <tr><td>-</td> <td>优惠券</td> <td>5元优惠券</td> <td>1000</td> <td>20%</td></tr> <tr><td>-</td> <td>空奖</td> <td>-</td> <td>5000</td> <td>30%</td></tr></tbody></table> <p>备注：每轮场次中奖概率之和必须为100%，否则剩余部分默认添加为空奖的中奖概率。</p> <h4 id="第五要素：均匀投奖"><a href="#第五要素：均匀投奖" class="header-anchor">#</a> 第五要素：均匀投奖</h4> <blockquote><p>如何均匀的抽走奖品?</p></blockquote> <p>答案: 均匀投奖。</p> <p>具体方式为拆分总奖品数量，到各个细致具体的时间段。以双十二幸运大转盘为例：</p> <table><thead><tr><th>场次</th> <th>奖品类型</th> <th>具体奖品</th> <th>奖品数量</th> <th>中奖概率</th> <th>投奖时间(默认提前5分钟投奖)</th> <th>投奖数量</th></tr></thead> <tbody><tr><td>00:00:00 至 23:59:59</td> <td>优惠券</td> <td>2元优惠券</td> <td>2000</td> <td>50%</td> <td>-</td> <td>-</td></tr> <tr><td>-</td> <td>-</td> <td>-</td> <td>-</td> <td>-</td> <td>00:00:00</td> <td>2000</td></tr> <tr><td>-</td> <td>-</td> <td>-</td> <td>-</td> <td>-</td> <td>06:00:00</td> <td>2000</td></tr> <tr><td>-</td> <td>-</td> <td>-</td> <td>-</td> <td>-</td> <td>12:00:00</td> <td>2000</td></tr> <tr><td>-</td> <td>-</td> <td>-</td> <td>-</td> <td>-</td> <td>18:00:00</td> <td>2000</td></tr></tbody></table> <p>这里我们就得到了抽奖的<strong>第五个要素：均匀投奖</strong>。</p> <h2 id="需求总结"><a href="#需求总结" class="header-anchor">#</a> 需求总结</h2> <p>通过上面的分析，我们得到抽奖五要素如下：</p> <table><thead><tr><th>抽奖五要素</th> <th>要素名称</th></tr></thead> <tbody><tr><td>第一要素</td> <td>活动</td></tr> <tr><td>第二要素</td> <td>场次</td></tr> <tr><td>第三要素</td> <td>奖品</td></tr> <tr><td>第四要素</td> <td>中奖概率</td></tr> <tr><td>第五要素</td> <td>均匀投奖</td></tr></tbody></table> <p>同时我们通过<strong>抽奖五要素</strong>也得到了<strong>通用抽奖工具</strong>配置一场抽奖活动的5个基本步骤：</p> <ol><li>活动配置</li> <li>场次配置</li> <li>奖品配置</li> <li>奖品中奖概率配置</li> <li>奖品投奖配置</li></ol> <h2 id="通用抽奖工具系统设计"><a href="#通用抽奖工具系统设计" class="header-anchor">#</a> 通用抽奖工具系统设计</h2> <p>需求已经分析完了，今天我们就来看看这通用抽奖工具具体的设计，分为如下三个部分：</p> <ul><li>DB设计</li> <li>配置后台设计</li> <li>接口设计</li></ul> <h2 id="db设计"><a href="#db设计" class="header-anchor">#</a> DB设计</h2> <p>第一要素<code>活动配置</code>的<code>抽奖活动表</code>：</p> <div class="language-sql extra-class"><pre class="language-sql"><code><span class="token comment">-- 通用抽奖工具(万能胶Glue) glue_activity 抽奖活动表</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>glue_activity<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'活动ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>serial_no<span class="token punctuation">`</span> <span class="token keyword">char</span><span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'活动编号(md5值中间16位)'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'活动名称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>description<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'活动描述'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>activity_type<span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'1'</span> <span class="token keyword">COMMENT</span> <span class="token string">'活动抽奖类型1: 按时间抽奖 2: 按抽奖次数抽奖 3:按数额范围区间抽奖'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>probability_type<span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'1'</span> <span class="token keyword">COMMENT</span> <span class="token string">'中奖概率类型1: static 2: dynamic'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>times_limit<span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'抽奖次数限制，0默认不限制'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>start_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'活动开始时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>end_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'活动结束时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>  <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 -1:deleted, 0:disable, 1:enable'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'抽奖活动表'</span><span class="token punctuation">;</span>
</code></pre></div><p>第二要素<code>场次配置</code>的<code>抽奖场次表</code>：</p> <div class="language-sql extra-class"><pre class="language-sql"><code><span class="token comment">-- 通用抽奖工具(万能胶Glue) glue_session 抽奖场次表</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>glue_session<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'场次ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>activity_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'活动ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>times_limit<span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'抽奖次数限制，0默认不限制'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>start_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'场次开始时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>end_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'场次结束时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>  <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 -1:deleted, 0:disable, 1:enable'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'抽奖场次表'</span><span class="token punctuation">;</span>
</code></pre></div><p>第三、四要素<code>奖品配置</code>的<code>抽奖场次奖品表</code>：</p> <div class="language-sql extra-class"><pre class="language-sql"><code><span class="token comment">-- 通用抽奖工具(万能胶Glue) glue_session_prizes 抽奖场次奖品表</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>glue_session_prizes<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>session_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'场次ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>node<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'节点标识 按时间抽奖: 空值, 按抽奖次数抽奖: 第几次参与值, 按数额范围区间抽奖: 数额区间上限值'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>prize_type<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'奖品类型 1:优惠券, 2:积分, 3:实物, 4:空奖 ...'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'奖品名称'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>pic_url<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'奖品图片'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">value</span><span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span> <span class="token keyword">COMMENT</span> <span class="token string">'奖品抽象值 优惠券:优惠券ID, 积分:积分值, 实物: sku ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>probability<span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'中奖概率1~100'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>  <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 -1:deleted, 0:disable, 1:enable'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'抽奖场次奖品表'</span><span class="token punctuation">;</span>

</code></pre></div><p>第五要素<code>均匀投奖</code>的<code>抽奖场次奖品定时投放器表</code>：</p> <div class="language-sql extra-class"><pre class="language-sql"><code><span class="token comment">-- 通用抽奖工具(万能胶Glue) glue_session_prizes_timer 抽奖场次奖品定时投放器表</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>glue_session_prizes_timer<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>session_prizes_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'抽奖场次奖品ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>delivery_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'定时投放奖品数量的时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>prize_quantity<span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'奖品数量'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_by<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'修改人staff_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>  <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 -1:deleted, 0:wait, 1:success'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'抽奖场次奖品定时投放器表'</span><span class="token punctuation">;</span>

</code></pre></div><p>其他表，抽奖记录&amp;奖品发放记录表：</p> <div class="language-sql extra-class"><pre class="language-sql"><code><span class="token comment">-- 通用抽奖工具(万能胶Glue) glue_user_draw_record 用户抽奖记录表</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>glue_user_draw_record<span class="token punctuation">`</span> <span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'自增ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>activity_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'活动ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>session_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'场次ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>prize_type_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'奖品类型ID'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>user_id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建人user_id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span><span class="token keyword">status</span><span class="token punctuation">`</span> <span class="token keyword">tinyint</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>  <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span> <span class="token keyword">COMMENT</span> <span class="token string">'状态 -1:未中奖, 1:已中奖 , 2: 发奖失败 , 3: 已发奖'</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>log<span class="token punctuation">`</span> <span class="token keyword">text</span> <span class="token keyword">COMMENT</span> <span class="token string">'操作信息等记录'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COMMENT</span><span class="token operator">=</span><span class="token string">'用户抽奖记录表'</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="配置后台设计"><a href="#配置后台设计" class="header-anchor">#</a> 配置后台设计</h2> <h4 id="创建活动"><a href="#创建活动" class="header-anchor">#</a> 创建活动</h4> <p align="center"><a href="http://cdn.tigerb.cn/20191229224816.png?imageMogr2/thumbnail/1934x1567!/format/webp/blur/1x0/quality/75|imageslim" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/20191229224816.png?imageMogr2/thumbnail/1934x1567!/format/webp/blur/1x0/quality/75|imageslim" width="66%"></a></p> <h4 id="创建活动场次"><a href="#创建活动场次" class="header-anchor">#</a> 创建活动场次</h4> <p align="center"><a href="http://cdn.tigerb.cn/20191230081157.png?imageMogr2/thumbnail/971x2069!/format/webp/blur/1x0/quality/75%7Cimageslim" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/20191230081157.png?imageMogr2/thumbnail/971x2069!/format/webp/blur/1x0/quality/75%7Cimageslim" width="66%"></a></p> <p align="center"><a href="http://cdn.tigerb.cn/20191229224543.png?imageMogr2/thumbnail/971x2214!/format/webp/blur/1x0/quality/75%7Cimageslim" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/20191229224543.png?imageMogr2/thumbnail/971x2214!/format/webp/blur/1x0/quality/75%7Cimageslim" width="66%"></a></p> <p align="center"><a href="http://cdn.tigerb.cn/20191229224834.png?imageMogr2/thumbnail/971x1693!/format/webp/blur/1x0/quality/75%7Cimageslim" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/20191229224834.png?imageMogr2/thumbnail/971x1693!/format/webp/blur/1x0/quality/75%7Cimageslim" width="66%"></a></p> <h4 id="活动列表"><a href="#活动列表" class="header-anchor">#</a> 活动列表</h4> <p align="center"><a href="http://cdn.tigerb.cn/20191229223706.png?imageMogr2/thumbnail/1338x761!/format/webp/blur/1x0/quality/75%7Cimageslim" data-lightbox="roadtrip"><img src="http://cdn.tigerb.cn/20191229223706.png?imageMogr2/thumbnail/1338x761!/format/webp/blur/1x0/quality/75%7Cimageslim" width="66%"></a></p> <h2 id="接口设计-3"><a href="#接口设计-3" class="header-anchor">#</a> 接口设计</h2> <ol><li>获取活动信息 GET {version}/glue/activity</li></ol> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>serial_no</td> <td>string</td> <td>Y</td> <td>活动编号</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;serial_no&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 活动编号&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 活动抽奖类型1: 按时间抽奖 2: 按抽奖次数抽奖 3:按数额范围区间抽奖&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 活动名称&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;description&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 活动描述&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;start_time&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 活动开始时间&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;end_time&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 活动开始时间&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;remaining_times&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 活动抽奖次数限制，0不限制&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;sessions_list&quot;</span><span class="token operator">:</span><span class="token punctuation">[</span>
            <span class="token punctuation">{</span>
                <span class="token property">&quot;start_time&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 场次开始时间&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;end_time&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 场次开始时间&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;remaining_times&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 场次抽奖次数限制，0不限制&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;prizes_list&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
                    <span class="token punctuation">{</span>
                        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 奖品名称&quot;</span><span class="token punctuation">,</span>
                        <span class="token property">&quot;pic_url&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 奖品图片&quot;</span>
                    <span class="token punctuation">}</span>
                <span class="token punctuation">]</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><ol start="2"><li>抽奖 POST {version}/glue/activity/draw</li></ol> <p>请求参数：</p> <table><thead><tr><th>字段</th> <th>类型</th> <th>是否必传</th> <th>描述</th></tr></thead> <tbody><tr><td>serial_no</td> <td>string</td> <td>Y</td> <td>活动编号</td></tr> <tr><td>uid</td> <td>number</td> <td>Y</td> <td>用户ID</td></tr></tbody></table> <p>响应内容：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token comment">// 中奖</span>
<span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;200&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;OK&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;serial_no&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, spu id&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;act_remaining_times&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 本活动抽奖剩余次数，0不限制&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;session_remaining_times&quot;</span><span class="token operator">:</span> <span class="token string">&quot;number, 本场次抽奖剩余次数，0不限制&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;prizes_info&quot;</span><span class="token operator">:</span> 
        <span class="token punctuation">{</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 奖品名称&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;pic_url&quot;</span><span class="token operator">:</span> <span class="token string">&quot;string, 奖品图片&quot;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// 未中奖</span>
<span class="token punctuation">{</span>
    <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;401&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="结语"><a href="#结语" class="header-anchor">#</a> 结语</h2> <p>活动营销系统中的第一个字系统<strong>通用抽奖工具</strong>今天讲完了，希望对大家有一定的帮助或启示。</p> <h1 id="秒杀服务"><a href="#秒杀服务" class="header-anchor">#</a> 秒杀服务</h1> <h2 id="前言-2"><a href="#前言-2" class="header-anchor">#</a> 前言</h2> <p>本文结构很简单：</p> <blockquote><p>5张图送你5种秒杀系统，再加点骚操作，再顺带些点心里话🤷‍♀️。</p></blockquote> <h2 id="一个简单的秒杀系统"><a href="#一个简单的秒杀系统" class="header-anchor">#</a> 一个简单的秒杀系统</h2> <p><strong>实现原理：</strong> 通过redis原子操作减库存</p> <p><strong>图一</strong></p><p align="center"><a href="http://cdn.tigerb.cn/20200501175532.png"><img src="http://cdn.tigerb.cn/20200501175532.png" width="100%"></a></p><p></p> <table><thead><tr><th>优点</th> <th>缺点</th></tr></thead> <tbody><tr><td>简单好用</td> <td>考验redis服务能力</td></tr></tbody></table> <table><thead><tr><th>是否公平</th></tr></thead> <tbody><tr><td>公平</td></tr> <tr><td>先到先得</td></tr></tbody></table> <p>我们称这类秒杀系统为：</p> <blockquote><p>简单秒杀系统</p></blockquote> <p>如果刚开始QPS并不高，redis完全抗的下来的情况，完全可以依赖这个「简单秒杀系统」。</p> <h2 id="一个够用的秒杀系统"><a href="#一个够用的秒杀系统" class="header-anchor">#</a> 一个够用的秒杀系统</h2> <p><strong>实现原理：</strong> 服务内存限流算法 + redis原子操作减库存</p> <p><strong>图二</strong></p><p align="center"><a href="http://cdn.tigerb.cn/20200501183037.png"><img src="http://cdn.tigerb.cn/20200501183037.png"></a></p><p></p> <table><thead><tr><th>优点</th> <th>缺点</th></tr></thead> <tbody><tr><td>简单好用</td> <td>-</td></tr></tbody></table> <table><thead><tr><th>是否公平</th></tr></thead> <tbody><tr><td>不是很公平</td></tr> <tr><td>相对的先到先得</td></tr></tbody></table> <p>我们称这类秒杀系统为：</p> <blockquote><p>够用秒杀系统</p></blockquote> <h2 id="性能再好点的秒杀系统"><a href="#性能再好点的秒杀系统" class="header-anchor">#</a> 性能再好点的秒杀系统</h2> <p><strong>实现原理：</strong> 服务本地内存原子操作减库存</p> <blockquote><p>服务本地内存的库存怎么来的？</p></blockquote> <p>活动开始前分配好每台机器的库存，推送到机器上。</p> <p><strong>图三</strong></p><p align="center"><a href="http://cdn.tigerb.cn/20200501200309.png"><img src="http://cdn.tigerb.cn/20200501200309.png"></a></p><p></p> <table><thead><tr><th>优点</th> <th>缺点</th></tr></thead> <tbody><tr><td>高性能</td> <td>不支持动态伸缩容(活动进行期间)，因为库存是活动开始前分配好的</td></tr> <tr><td>释放redis压力</td> <td>-</td></tr></tbody></table> <table><thead><tr><th>是否公平</th></tr></thead> <tbody><tr><td>不是很公平</td></tr> <tr><td>不是绝对的先到先得</td></tr></tbody></table> <p>我们称这类秒杀系统为：</p> <blockquote><p>预备库存秒杀系统</p></blockquote> <h2 id="支持动态伸缩容的秒杀系统"><a href="#支持动态伸缩容的秒杀系统" class="header-anchor">#</a> 支持动态伸缩容的秒杀系统</h2> <p><strong>实现原理：</strong> 服务本地协程Coroutine<strong>定时redis原子操作减部分库存</strong>到本地内存 + 服务本地内存原子操作减库存</p> <p><strong>图四</strong></p><p align="center"><a href="http://cdn.tigerb.cn/20200501200846.png"><img src="http://cdn.tigerb.cn/20200501200846.png"></a></p><p></p> <table><thead><tr><th>优点</th> <th>缺点</th></tr></thead> <tbody><tr><td>高性能</td> <td>支持动态伸缩容(活动进行期间)</td></tr> <tr><td>释放redis压力</td> <td>-</td></tr> <tr><td><strong>具备通用性</strong></td> <td>-</td></tr></tbody></table> <table><thead><tr><th>是否公平</th></tr></thead> <tbody><tr><td>不是很公平，但是好了点</td></tr> <tr><td>几乎先到先得</td></tr></tbody></table> <p>我们称这类秒杀系统为：</p> <blockquote><p>实时预备库存秒杀系统</p></blockquote> <h2 id="公平的秒杀系统"><a href="#公平的秒杀系统" class="header-anchor">#</a> 公平的秒杀系统</h2> <p><strong>实现原理：</strong> 服务本地Goroutine<strong>定时同步是否售罄</strong>到本地内存 + 队列 + 排队成功轮训(或主动Push)结果</p> <p><strong>图五</strong></p><p align="center"><a href="http://cdn.tigerb.cn/20200502195413.png"><img src="http://cdn.tigerb.cn/20200502195413.png"></a></p><p></p> <table><thead><tr><th>优点</th> <th>缺点</th></tr></thead> <tbody><tr><td>高性能</td> <td>开发成本高(需主动通知或轮训排队结果)</td></tr> <tr><td>真公平</td> <td>-</td></tr> <tr><td><strong>具备通用性</strong></td> <td>-</td></tr></tbody></table> <table><thead><tr><th>是否公平</th></tr></thead> <tbody><tr><td>很公平</td></tr> <tr><td>绝对的先到先得</td></tr></tbody></table> <p>我们称这类秒杀系统为：</p> <blockquote><p>公平排队秒杀系统</p></blockquote> <h2 id="骚操作"><a href="#骚操作" class="header-anchor">#</a> 骚操作</h2> <blockquote><p>上面的秒杀系统还不够完美吗？</p></blockquote> <p>答案：是的。</p> <blockquote><p>还有什么优化的空间？</p></blockquote> <p>答案：静态化获取秒杀活动信息的接口。</p> <blockquote><p>静态化是什么意思?</p></blockquote> <p>答案：比如获取秒杀活动信息是通过接口 <code>https://seckill.skrshop.tech/v1/acticity/get</code> 获取的。现在呢，我们需要通过<code>https://static-api.skrshop.tech/seckill/v1/acticity/get</code> 这个接口获取。有什么区别呢？看下面：</p> <table><thead><tr><th>服务名</th> <th>接口</th> <th>数据存储位置</th></tr></thead> <tbody><tr><td>秒杀服务</td> <td>https://seckill.skrshop.tech/v1/acticity/get</td> <td>秒杀服务内存或redis等</td></tr> <tr><td>接口静态化服务</td> <td>https://static-api.skrshop.tech/seckill/v1/acticity/get</td> <td>CDN、本地文件</td></tr></tbody></table> <p><strong>以前是这样</strong></p><p align="center"><a href="http://cdn.tigerb.cn/20200502195950.png"><img src="http://cdn.tigerb.cn/20200502195950.png" width="66%"></a></p><p></p> <p><strong>变成了这样</strong></p><p align="center"><a href="http://cdn.tigerb.cn/20200502200723.png"><img src="http://cdn.tigerb.cn/20200502200723.png" width="100%"></a></p><p></p> <p>结果：可以通过接口<code>https://static-api.skrshop.tech/seckill/v1/acticity/get</code>就获取到了秒杀活动信息，流量都分摊到了cdn，秒杀服务自身没了这部分的负载。</p> <blockquote><p>小声点说：“秒杀结果我也敢推CDN😏😏😏。”</p></blockquote> <div class="language- extra-class"><pre class="language-text"><code>备注：
之后我们会分享`如何用Golang设计一个好用的「接口静态化服务」`。
</code></pre></div><h1 id="总结-2"><a href="#总结-2" class="header-anchor">#</a> 总结</h1> <p>上面我们得到了如下几类<code>秒杀系统</code></p> <table><thead><tr><th>秒杀系统</th></tr></thead> <tbody><tr><td>简单秒杀系统</td></tr> <tr><td>够用秒杀系统</td></tr> <tr><td>预备库存秒杀系统</td></tr> <tr><td>实时预备库存秒杀系统</td></tr> <tr><td>公平排队秒杀系统</td></tr></tbody></table> <p>我想说的是里面没有最好的方案，也没有最坏的方案，只有<strong>适合你</strong>的。</p> <p>拿<code>先到先得</code>来说，一定要看你们的产品对外宣传，切勿上来就追逐绝对的先到先得。其实你看所有的方案，相对而言都是“先到先得”，比如，活动开始一个小时了你再来抢，那相对于准时的用户自然抢不过，对吧。</p> <p>又如<code>预备库存秒杀系统</code>，虽然不支持动态伸缩容。但是如果你的环境满足如下任意条件，就完全够用了。</p> <ul><li>秒杀场景结束时间之快，通常几秒就结束了，真实活动可能会发生如下情况：
<ul><li>服务压力大还没挂：根本就来不及动态伸缩容</li> <li>服务压力大已经挂了：可以先暂停活动，服务起来&amp;扩容结束，用剩余库存重新推送</li></ul></li> <li>运维自身不具备动态伸缩容的能力</li></ul> <p>所以:</p> <blockquote><p>合适好用就行，切勿过度设计。</p></blockquote> <h1 id="交易中心"><a href="#交易中心" class="header-anchor">#</a> 交易中心</h1> <h2 id="常见第三方支付流程"><a href="#常见第三方支付流程" class="header-anchor">#</a> 常见第三方支付流程</h2> <p>这几年的工作中一直与支付打交到，借着 <a href="https://github.com/skr-shop/manuals" target="_blank" rel="noopener noreferrer">skr-shop<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a> 这个项目来与大家一起分享探索一下支付系统该怎么设计、怎么做。我们先从支付的一些常见流程出发分析，找出这些支付的共性，抽象后再去探讨具体的数据库设计、代码结构设计。</p> <p>相关项目：</p> <ul><li><a href="https://github.com/helei112g/payment" target="_blank" rel="noopener noreferrer">PHP 版本的支付SDK<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li> <li><a href="https://github.com/skr-shop/fool-pay" target="_blank" rel="noopener noreferrer">Go 版本的支付SDK-开发中<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul> <blockquote><p>支付整体而言的一个流程是：给第三方发起了一笔交易，用户通过第三方完成支付，第三方告诉我支付成功，我把用户购买的产品给用户。</p></blockquote> <p><img src="https://dayutalk.cn/img/pay-1.jpg" alt="pay-1"></p> <p>看似简单的流程，这里边不同的支付机构却有不同的处理。下面以我接触过的一些支付来总结一下</p> <h3 id="国内支付"><a href="#国内支付" class="header-anchor">#</a> 国内支付</h3> <p>国内的典型支付代表是：<strong>支付宝</strong>、<strong>微信</strong>、<strong>银行</strong>(以招商银行为例)，由于国内的支付都支持多种渠道的支付方式，为了描述简单，我们均以pc上的支付为例进行讲解。</p> <h4 id="支付宝"><a href="#支付宝" class="header-anchor">#</a> 支付宝</h4> <p>支付宝的接入是我觉得最简单的一种支付。对于在PC上的支付能力，支付宝提供了【电脑支付】。当用户下单后，商户系统根据支付宝的规则构建好一个url，用户跳转到这个url后进入到支付宝的支付页面，然后完成支付流程。</p> <p>在支付成功后，支付宝会通过 <strong>同步通知</strong>、<strong>异步通知</strong> 两种方式告诉商户系统支付成功，并且两种通知方式的结果都是可信的，而且异步通知的消息延迟也非常短暂。</p> <p>对于退款流程，支付宝支持全额、部分退款。并且能够根据商户的退款单号区分是否是同一笔退款进而避免了重复退款的可能。支付的退款是调用后同步返回结果，不会异步通知。</p> <h4 id="微信支付"><a href="#微信支付" class="header-anchor">#</a> 微信支付</h4> <p>微信并没有提供真的PC支付能力，但是我们可以利用【扫码支付】来达成电脑支付的目的。扫码支付有两种模式，这里以模式二为例。</p> <p>微信调用下单接口获取到这个二维码链接，然后用户扫码后，进入支付流程。完成支付后微信会 <strong>异步通知</strong>，但是这里并没有 <strong>同步通知</strong>，因此前端页面只能通过定时轮训的方式检查这笔交易是否支付，直到查询到成功、或者用户主动关闭页面。</p> <p>退款流程与支付宝最大的不同是，有一个 <strong>异步通知</strong> 需要商户系统进行处理。</p> <blockquote><p>第一个不同点：</p> <ol><li>异步通知的接口需要处理多种不同类型的异步消息</li></ol></blockquote> <h4 id="招商银行"><a href="#招商银行" class="header-anchor">#</a> 招商银行</h4> <p>随着在线支付在国内的蓬勃发展，各家银行也是不断推出自己的在线支付能力。其中的佼佼者当属 <strong>招商银行</strong>。大家经常用的滴滴上面就有该支付方式，可以体验一下。</p> <p>招商支付使用的是银行卡，因此首次用户必须进行绑卡。因此这里可能就多了一个流程，首先得记录用户是否绑过卡，然后用于签名的公钥会发生变化，需要定期更新。</p> <p>招商所有平台的支付体验都是一致的，会跳转到招行的H5页面完成逻辑，支付成功后并不会自动跳回商户，也就是没有 <strong>同步通知</strong>，它的支付结果只会走异步通知流程，延迟非常短暂。</p> <p>退款流程与支付宝一样，也是同步返回退款结果，没有异步通知。</p> <blockquote><p>第二个不同点：</p> <ol><li>支付前需要检查用户是否签约过，有签约流程</li></ol></blockquote> <h4 id="小结"><a href="#小结" class="header-anchor">#</a> 小结</h4> <p>国内在线支付流程相对都比较完善，接入起来也非常容易。需要注意的一点是：退款后之前支付的单子依然是支付成功状态，并不会变成退款状态。因为退款与支付属于不同的交易。</p> <p>这一点基本上是国内在线支付的通用做法。</p> <h3 id="国际支付"><a href="#国际支付" class="header-anchor">#</a> 国际支付</h3> <p>国际支付的平台非常多，包括像支付宝、微信也在扩展这一块市场。我以我接触的几家支付做一个简单的总结。</p> <h4 id="worldpay"><a href="#worldpay" class="header-anchor">#</a> WorldPay</h4> <p>这是比较出名的一家国际支付公司，它主要做的是银行卡支付，公司在英国</p> <p>支付流程上，也是根据规则构建好请求的url后，直接跳转到 <strong>WorldPay</strong> 的页面，通过信用卡完成支付。这里比较麻烦的处理机制是：支付成功后，他首次给你的异步/同步消息通知并不能作为支付成功的依据。真的从银行确认划款成功后，才会给出真的支付成功通知。这中间还可能会异步通知告诉你支付请求被拒绝。最头痛的是不同状态的异步消息时间间隔都是按照分钟以上级别的延迟来计算</p> <p>退款流程上，状态跟微信一样，需要通过异步消息来确认退款状态。其次它的不同点在于无法根据商户退款单号来确认是否已经发起过退款，因此对于它来说只要请求一次退款接口，那它就默认发起了一次退款。</p> <blockquote><p>第三、四不同点：</p> <ol><li><p>支付成功后的通知状态有多种，涉及到商户系统业务流程的特殊处理</p></li> <li><p>退款不支持商户退款单号，无法支持防重复退款需要商户自己处理</p></li></ol></blockquote> <h4 id="assist"><a href="#assist" class="header-anchor">#</a> Assist</h4> <p>这是俄罗斯的一家支付公司，这也是一家搞死人不偿命的公司，看下面介绍</p> <p>它的支付发起是需要构建一个form表单，向它post支付相关的数据。成功后会跳转到它的支付页，用户完成支付即可。对于 <strong>同步通知</strong>，它需要用户手动触发跳回商户，与招商的逻辑很像，同步也仅仅是做返回并不会真的告知支付结果。<strong>异步通知</strong> 才是真的告知支付状态。比较恶心的是，支付时必须传入指定格式的商品信息，这会在部分退款时用到。</p> <p>现在来说退款，退款也是与 <strong>WorldPay</strong> 一样，不支持商户的退款单号，因此防重方面也许自己的系统进行设计。并且如果是部分退款，需要传入指定的退款商品，这就会出现一个非常尴尬的局面：部分退款的金额与任何一个商品金额都对应不上，退款则会失败。</p> <blockquote><p>第五个不同点：</p> <ol><li>部分退款时需要传入部分退款的商品信息，并且金额要一致</li></ol></blockquote> <h4 id="doku"><a href="#doku" class="header-anchor">#</a> Doku</h4> <p>接下来再来聊聊印尼的这家支付机构 <strong>doku</strong>。由于印尼这个国家信用卡的普及程度并不高，它的在线支付提供一种超商支付方式。</p> <p>什么是超商支付呢？也就是用户在网络上完成下单后，会获取到一个二维码或者条形码。用户拿着这个条形码到超商（711、全家这种）通过收银员扫码，付现金给超商，完成支付流程。</p> <p>这种方式带来的问题是，用户长时间不去支付，导致订单超时关单后才去付款。对整个业务流程以及用户体验带来很多伤害。</p> <p>再来说退款，由于存在超商这种支付方式，导致这种支付无法支持在线自动退款，需要人工收集用户银行卡信息，然后完成转账操作。非常痛苦不堪。</p> <blockquote><p>第六个不同点：</p> <ol><li>线上没有付款，只有获取付款码，退款需要通过人工操作</li></ol></blockquote> <h4 id="amazonpay"><a href="#amazonpay" class="header-anchor">#</a> AmazonPay</h4> <p>亚马逊出品，与支付宝非常类似。提供的是集成式的钱包流程。</p> <p>支付时直接构建一个url，然后跳转到亚马逊即可完成支付。它还提供一种授权模式，能够不用跳转amazon，再商户端即完成支付。</p> <p>支付成功后也会同步跳转，<strong>同步通知</strong> 的内容可以作为支付是否成功的判断依据。经过实际检查 <strong>异步通知</strong> 的到达会稍有延迟，大概10s以内。</p> <p>退款方面也支持商户退款单号可以依赖此进行防重。但是退款的状态也是基于异步来的。</p> <h3 id="总结-3"><a href="#总结-3" class="header-anchor">#</a> 总结</h3> <p>这其中还有一些国际支付，如：<strong>PayPal</strong>、<strong>GooglePay</strong>、<strong>PayTM</strong> 等知名支付机构没有进行介绍，是因为基本它们的流程也都在上面的模式之中。我们后续的代码结构设计、数据库设计都基于满足上面的各种支付模型来完成设计。</p> <p>最后，赠送大家一副脑图，这是接入一家支付时必须弄清楚的问题清单</p> <p><img src="https://dayutalk.cn/img/pay-2.png" alt="pay-2"></p> <h2 id="支付系统设计"><a href="#支付系统设计" class="header-anchor">#</a> 支付系统设计</h2> <p>文中我们从严谨的角度一步步聊到支付如何演变成独立的系统。内容包括：系统演进过程、接口设计、数据库设计以及代码如何组织的示例。若有不足之处，欢迎讨论共同学习。</p> <h3 id="从模块到服务"><a href="#从模块到服务" class="header-anchor">#</a> 从模块到服务</h3> <p>我记得最开始工作的时候，所有的功能：加购物车/下单/支付 等逻辑都是放在一个项目里。如果一个新的项目需要某个功能，就把这个部分的功能包拷贝到新的项目。数据库也原封不动的拷贝过来，稍微根据需求改改。</p> <p>这就是所谓的 <strong>单体应用</strong> 时代，随着公司产品线开始多元，每条产品线都需要用到支付服务。如果支付模块调整了代码，那么就会处处改动、处处测试。另一方面公司的交易数据割裂在不同的系统中，无法有效汇总统一分析、管理。</p> <p>这时就到了系统演进的时候，我们把每个产品线的支付模块抽离成统一的服务。对自己公司内部提供统一的API使用，可以对这些API进一步包装成对应的SDK，供内部业务线快速接入。这里服务使用HTTP或者是RPC协议都可以根据公司实际情况决定。不过如果考虑到未来给第三方使用，建议使用HTTP协议，</p> <p><strong>系统的演变过程：</strong></p> <p><img src="https://dayutalk.cn/img/image-20190309104541749.png" alt="image-20190309104541749"></p> <p>总结下，将支付单独抽离成服务后，带来好处如下：</p> <ol><li>避免重复开发，数据隔离的现象出现；</li> <li>支付系统周边功能演进更容易，整个系统更完善丰满。如：对账系统、实时交易数据展示；</li> <li>随时可对外开发，对外输出Paas能力，成为有收入的项目；</li> <li>专门的团队进行维护，系统更有机会演进成顶级系统；</li> <li>公司重要账号信息保存一处，风险更小。</li></ol> <h3 id="系统能力"><a href="#系统能力" class="header-anchor">#</a> 系统能力</h3> <p>如果我们接手该需求，需要为公司从零搭建支付系统。我们该从哪些方面入手？这样的系统到底需要具备什么样的能力呢？</p> <p>首先支付系统我们可以理解成是一个适配器。他需要把很多第三方的接口进行统一的整合封装后，对内部提供统一的接口，减少内部接入的成本。做为一个最基本的支付系统。需要对内提供如下接口出来：</p> <ol><li>发起支付，我们取名：<code>/gopay</code></li> <li>发起退款，我们取名：<code>/refund</code></li> <li>接口异步通知，我们取名：<code>/notify/支付渠道/商户交易号</code></li> <li>接口同步通知，我们取名：<code>/return/支付渠道/商户交易号</code></li> <li>交易查询，我们取名：<code>/query/trade</code></li> <li>退款查询，我们取名：<code>/query/refund</code></li> <li>账单获取，我们取名：<code>/query/bill</code></li> <li>结算明细，我们取名：<code>/query/settle</code></li></ol> <p>一个基础的支付系统，上面8个接口是肯定需要提供的（这里忽略某些支付中的转账、绑卡等接口）。现在我们来基于这些接口看看都有哪些系统会用到。</p> <p><img src="https://dayutalk.cn/img/image-20190309111001880.png" alt="image-20190309111001880"></p> <p>下面按照系统维度，介绍下这些接口如何使用，以及内部的一些逻辑。</p> <h4 id="应用系统"><a href="#应用系统" class="header-anchor">#</a> 应用系统</h4> <p>一般支付网关会提供两种方式让应用系统接入：</p> <ol><li>网关模式，也就是应用系统自己需要开发一个收银台；（适合提供给第三方）</li> <li>收银台模式，应用系统直接打开支付网关的统一收银台。（内部业务）</li></ol> <p>下面为了讲清楚设计思路，我们按照 <strong>网关模式</strong> 进行讲解。</p> <p>对于应用系统它需要能够请求支付，也就是调用 <code>gopay</code> 接口。这个接口会处理商户的数据，完成后会调用第三方网关接口，并将返回结果统一处理后返回给应用方。</p> <p>这里需要注意，第三方针对支付接口根据我的经验大致有以下情况：</p> <ol><li>支付时，不需要调用第三方，按照规则生成数据即可；</li> <li>支付时，需要调用第三方多个接口完成逻辑（这可能比较慢，大型活动时需要考虑限流/降配）；</li> <li>返回的数据是一个url，可直接跳转到第三方完成支付（wap/pc站）；</li> <li>返回的数据是xml/json结构，需要拼装或作为参数传给她的sdk（app）。</li></ol> <p>这里由于第三方返回结构的不统一，我们需要统一处理成统一格式，返回给商户端。我推荐使用json格式。</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;errno&quot;</span><span class="token operator">:</span><span class="token number">0</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span><span class="token string">&quot;ok&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;data&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>

    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>我们把所有的变化封装在 <strong>data</strong> 结构中。举个例子，如果返回的一个url。只需要应用程序发起 <strong>GET</strong> 请求。我们可以这样返回：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;errno&quot;</span><span class="token operator">:</span><span class="token number">0</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span><span class="token string">&quot;ok&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;data&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;url&quot;</span><span class="token operator">:</span><span class="token string">&quot;xxxxx&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;method&quot;</span><span class="token operator">:</span><span class="token string">&quot;GET&quot;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>如果是返回的结构，需要应用程序直接发起 <strong>POST</strong> 请求。我们可以这样返回：</p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;errno&quot;</span><span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span>
    <span class="token property">&quot;msg&quot;</span><span class="token operator">:</span><span class="token string">&quot;ok&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;data&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;from&quot;</span><span class="token operator">:</span><span class="token string">&quot;&lt;form action=&quot;</span>xxx<span class="token string">&quot; method=&quot;</span>POST<span class="token string">&quot;&gt;xxxxx&lt;/form&gt;&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;method&quot;</span><span class="token operator">:</span><span class="token string">&quot;POST&quot;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><p>这里的 <strong>form</strong> 字段，生成了一个form表单，应用程序拿到后可直接显示然后自动提交。当然封装成 from表单这一步也可以放在商户端进行。</p> <p>上面的数据格式仅仅是一个参考。大家可根据自己的需求进行调整。</p> <p>一般应用系统除了会调用发起支付的接口外，可能还需要调用 <strong>支付结果查询接口</strong>。当然大多数情况下不需要调用，应用系统对交易的状态只应该依赖自己的系统状态。</p> <h4 id="对账系统"><a href="#对账系统" class="header-anchor">#</a> 对账系统</h4> <p>对于对账，一般分为两个类型：<strong>交易对账</strong> 与 <strong>结算对账</strong></p> <h5 id="交易对账"><a href="#交易对账" class="header-anchor">#</a> 交易对账</h5> <p>交易对账的核心点是：<strong>检查每一笔交易是否正确</strong>。它主要目的是看我们系统中的每一笔交易与第三方的每一笔交易是否一致。</p> <p>这个检查逻辑很简单，对两份账单数据进行比较。它主要是使用 <code>/query/bill</code> 接口，拿到在第三方那边完成的交易数据。然后跟我方的交易成功数据进行比较。检查是否存在误差。</p> <p>这个逻辑非常简单，但是有几点需要大家注意：</p> <ol><li>我方的数据需要正常支付数据+重复支付数据的总和；</li> <li>对账检查不成功主要包括：<strong>金额不对</strong>、<strong>第三方没有找到对应的交易数据</strong>、<strong>我方不存在对应的交易数据</strong>。</li></ol> <p>针对这些情况都需要有对应的处理手段进行处理。在我的经验中上面的情况都有过遇到。</p> <p><strong>金额不对</strong>：主要是由于第三方的问题，可能是系统升级故障、可能是账单接口金额错误；</p> <p><strong>第三方无交易数据：</strong> 可能是拉去的账单时间维度问题（比如存在时差），这种时区问题需要自己跟第三方确认找到对应的时间差。也可能是被攻击，有人冒充第三方异步通知（说明系统校验机制又问题或者密钥泄漏了）。</p> <p><strong>自己系统无交易数据：</strong> 这种原因可能是第三方通知未发出或者未正确处理导致的。</p> <p>上面这些问题的处理绝大部份都可以依赖 <code>query/trade</code> <code>query/refund</code> 来完成自动化处理。</p> <h5 id="结算对账"><a href="#结算对账" class="header-anchor">#</a> 结算对账</h5> <p>那么有了上面的 <strong>交易对账</strong> 为什么还需要 <strong>结算对账</strong> 呢？这个系统又是干嘛的？先来看下结算的含义。</p> <blockquote><p>结算，就是第三方网关在固定时间点，将T+x或其它约定时间的金额，汇款到公司账号。</p></blockquote> <p>下面我们假设结算周期是： <strong>T+1</strong>。结算对账主要使用到的接口是 <code>/query/settle</code>，这个接口获取的主要内容是：每一笔结算的款项都是由哪些笔交易组成（交易成功与退款数据）。以及本次结算扣除多少手续费用。</p> <p>它的逻辑其实也很简单。我们先从自己的系统按照 <strong>T+1</strong> 的结算周期，计算出对方应该汇款给我们多少金额。然后与刚刚接口获取到的数据金额比较：</p> <blockquote><p>银行收款金额 + 手续费 = 我方系统计算的金额</p></blockquote> <p>这一步检查通过后，说明金额没有问题。接下来需要检查本次结算下的每一笔订单是否一致。</p> <p>结算系统是 <strong>强依赖</strong> 对账系统的。如果对账发现异常，那么结算金额肯定会出现异常。另外结算需要注意的一些问题是：</p> <ul><li>银行可能会自行退款给用户，因为用户可直接向自己发卡行申请退款；</li> <li>结算也存在时区差问题；</li> <li>结算接口中的明细交易状态与我方并不完全一致。比如：银行结算时发现某笔退款完成，但我方系统在进行比较时按照未退款完成的逻辑在处理。</li></ul> <p>针对上面的问题，大家根据自己的业务需求需要做一些方案来进行自动化处理。</p> <h4 id="财务系统"><a href="#财务系统" class="header-anchor">#</a> 财务系统</h4> <p>财务系统有很多内部业务，我这里只聊与支付系统相关的。（当然上面的对账系统也可以算是财务范畴）。</p> <p>财务系统与支付主要的一个关系点在于校验交易、以及退款。这里校验交易可以使用 <code>query/trade</code> <code>query/refund</code>这两个接口来完成。这个逻辑过程就不需要说了。下面重点说下退款。</p> <p>我看到很多的系统退款是直接放在了应用里边，用户申请退款直接就调用退款接口进行退款。这样的风险非常高。支付系统的关于资金流向的接口一定要慎重，不能过多的直接暴露给外部，带来风险。</p> <p>退款的功能应该是放到财务系统来做。这样可以走内部的审批流程（是否需要根据业务来），并且在财务系统中可以进行更多检查来觉得是否立即进行退款，或者进入等待、拒绝等流程。</p> <h4 id="第三方网关"><a href="#第三方网关" class="header-anchor">#</a> 第三方网关</h4> <p>针对第三方主要使用到的其实就是异步通知与同步通知两个接口。这一部分的逻辑其实非常简单。就是根据第三方的通知完成交易状态的变更。以及通知到自己对应的应用系统。</p> <p>这部分比较复杂的是，第三方的通知数据结构不统一、通知的类型不统一。比如：有的退款是同步返回结果、有的是异步返回结果。这里如何设计会在后面的 <strong>系统设计</strong> 中给出答案。</p> <h3 id="数据库设计"><a href="#数据库设计" class="header-anchor">#</a> 数据库设计</h3> <p>数据的设计是按照：交易、退款、日志 来设计的。对于上面说到的对账等功能并没有。这部分不难大家可以自行设计，按照上面讲到的思路。主要的表介绍如下：</p> <ul><li><code>pay_transaction</code> 记录所有的交易数据。</li> <li><code>pay_transaction_extension</code> 记录每次向第三方发起交易时，生成的交易号</li> <li><code>pay_log_data</code> 所有的日志数据，如：支付请求、退款请求、异步通知等</li> <li><code>pay_repeat_transaction</code> 重复支付的数据</li> <li><code>pay_notify_app_log</code> 通知应用程序的日志</li> <li><code>pay_refund</code> 记录所有的退款数据</li></ul> <p><strong>具体的表结构：</strong></p> <div class="language-sql extra-class"><pre class="language-sql"><code><span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table 创建支付流水表</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>pay_transaction<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">BIGINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>app_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'应用id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>pay_method_id<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付方式id，可以用来识别支付，如：支付宝、微信、Paypal等'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>app_order_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'应用方订单号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'本次交易唯一id，整个支付系统唯一，生成他的原因主要是 order_id对于其它应用来说可能重复'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>total_fee<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付金额，整数方式保存'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>scale<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'金额对应的小数位数'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>currency_code<span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'CNY'</span> <span class="token keyword">COMMENT</span> <span class="token string">'交易的币种'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>pay_channel<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'选择的支付渠道，比如：支付宝中的花呗、信用卡等'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>expire_time<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'订单过期时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>return_url<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付后跳转url'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>notify_url<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付后，异步通知url'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>email<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'用户的邮箱'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>sing_type<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'RSA'</span> <span class="token keyword">COMMENT</span> <span class="token string">'采用的签方式：MD5 RSA RSA2 HASH-MAC等'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>intput_charset<span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'UTF-8'</span> <span class="token keyword">COMMENT</span> <span class="token string">'字符集编码方式'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>payment_time<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'第三方支付成功的时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>notify_time<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'收到异步通知的时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>finish_time<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'通知上游系统的时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>trade_no<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'第三方的流水号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>transaction_code<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'真实给第三方的交易code，异步通知的时候更新'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>order_status<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'0:等待支付，1:待付款完成， 2:完成支付，3:该笔交易已关闭，-1:支付失败'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_ip<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建的ip，这可能是自己服务的ip'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>update_ip<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新的ip'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">UNIQUE</span> <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>uniq_tradid<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_trade_no<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>trade_no<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_ctime<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>create_at<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span>
<span class="token keyword">DEFAULT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token operator">=</span> utf8mb4
<span class="token keyword">COMMENT</span> <span class="token operator">=</span> <span class="token string">'发起支付的数据'</span><span class="token punctuation">;</span>

<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table 交易扩展表</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>pay_transaction_extension<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">BIGINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统唯一交易id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>pay_method_id<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>transaction_code<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'生成传输给第三方的订单号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>call_num<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'发起调用的次数'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>extension_data<span class="token punctuation">`</span> <span class="token keyword">TEXT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'扩展内容，需要保存：transaction_code 与 trade no 的映射关系，异步通知的时候填充'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_ip<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建ip'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_trads<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>pay_status<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">UNIQUE</span> <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>uniq_code<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>transaction_code<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span>
<span class="token keyword">DEFAULT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token operator">=</span> utf8mb4
<span class="token keyword">COMMENT</span> <span class="token operator">=</span> <span class="token string">'交易扩展表'</span><span class="token punctuation">;</span>

<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table 交易系统全部日志</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>pay_log_data<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">BIGINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>app_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'应用id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>app_order_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'应用方订单号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'本次交易唯一id，整个支付系统唯一，生成他的原因主要是 order_id对于其它应用来说可能重复'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>request_header<span class="token punctuation">`</span> <span class="token keyword">TEXT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'请求的header 头'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>request_params<span class="token punctuation">`</span> <span class="token keyword">TEXT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付的请求参数'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>log_type<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'日志类型，payment:支付; refund:退款; notify:异步通知; return:同步通知; query:查询'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_ip<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建ip'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_tradt<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>log_type<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span>
<span class="token keyword">DEFAULT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token operator">=</span> utf8mb4
<span class="token keyword">COMMENT</span> <span class="token operator">=</span> <span class="token string">'交易日志表'</span><span class="token punctuation">;</span>


<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table 重复支付的交易</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>pay_repeat_transaction<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">BIGINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>app_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'应用的id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'系统唯一识别交易号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>transaction_code<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付成功时，该笔交易的 code'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>trade_no<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'第三方对应的交易号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>pay_method_id<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付方式'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>total_fee<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'交易金额'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>scale<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'小数位数'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>currency_code<span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'CNY'</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付选择的币种，CNY、HKD、USD等'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>payment_time<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'第三方交易时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>repeat_type<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">1</span> <span class="token keyword">COMMENT</span> <span class="token string">'重复类型：1同渠道支付、2不同渠道支付'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>repeat_status<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'处理状态,0:未处理；1:已处理'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_trad<span class="token punctuation">`</span> <span class="token punctuation">(</span> <span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_method<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>pay_method_id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_time<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>create_at<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span>
<span class="token keyword">DEFAULT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token operator">=</span> utf8mb4
<span class="token keyword">COMMENT</span> <span class="token operator">=</span> <span class="token string">'记录重复支付'</span><span class="token punctuation">;</span>


<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table 通知上游应用日志</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>pay_notify_app_log<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">BIGINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>app_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'应用id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>pay_method_id<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付方式'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'交易号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>transaction_code<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付成功时，该笔交易的 code'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>sign_type<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'RSA'</span> <span class="token keyword">COMMENT</span> <span class="token string">'采用的签名方式：MD5 RSA RSA2 HASH-MAC等'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>input_charset<span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'UTF-8'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>total_fee<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'涉及的金额，无小数'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>scale<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'小数位数'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>pay_channel<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付渠道'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>trade_no<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'第三方交易号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>payment_time<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>notify_type<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'paid'</span> <span class="token keyword">COMMENT</span> <span class="token string">'通知类型，paid/refund/canceled'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>notify_status<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'INIT'</span> <span class="token keyword">COMMENT</span> <span class="token string">'通知支付调用方结果；INIT:初始化，PENDING: 进行中；  SUCCESS：成功；  FAILED：失败'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_trad<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_app<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>app_id<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>notify_status<span class="token punctuation">`</span><span class="token punctuation">)</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_time<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>create_at<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span>
<span class="token keyword">DEFAULT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token operator">=</span> utf8mb4
<span class="token keyword">COMMENT</span> <span class="token operator">=</span> <span class="token string">'支付调用方记录'</span><span class="token punctuation">;</span>


<span class="token comment">-- -----------------------------------------------------</span>
<span class="token comment">-- Table 退款</span>
<span class="token comment">-- -----------------------------------------------------</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>pay_refund<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">BIGINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>app_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'应用id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>app_refund_no<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'上游的退款id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'交易号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>trade_no<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'第三方交易号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>refund_no<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付平台生成的唯一退款单号'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>pay_method_id<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'支付方式'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>pay_channel<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">64</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'选择的支付渠道，比如：支付宝中的花呗、信用卡等'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>refund_fee<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'退款金额'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>scale<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'小数位数'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>refund_reason<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">128</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'退款理由'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>currency_code<span class="token punctuation">`</span> <span class="token keyword">CHAR</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'CNY'</span> <span class="token keyword">COMMENT</span> <span class="token string">'币种，CNY  USD HKD'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>refund_type<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'退款类型；0:业务退款; 1:重复退款'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>refund_method<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">1</span> <span class="token keyword">COMMENT</span> <span class="token string">'退款方式：1自动原路返回; 2人工打款'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>refund_status<span class="token punctuation">`</span> <span class="token keyword">TINYINT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'0未退款; 1退款处理中; 2退款成功; 3退款不成功'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_at<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'创建时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>update_at<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'更新时间'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>create_ip<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'请求源ip'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>update_ip<span class="token punctuation">`</span> <span class="token keyword">INT</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">COMMENT</span> <span class="token string">'请求源ip'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">UNIQUE</span> <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>uniq_refno<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>refund_no<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_trad<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>transaction_id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_status<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>refund_status<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> <span class="token punctuation">`</span>idx_ctime<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>create_at<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span>
<span class="token keyword">DEFAULT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token operator">=</span> utf8mb4
<span class="token keyword">COMMENT</span> <span class="token operator">=</span> <span class="token string">'退款记录'</span><span class="token punctuation">;</span>
</code></pre></div><p>表的使用逻辑进行下方简单描述：</p> <p><strong>支付</strong>，首先需要记录请求日志到 <code>pay_log_data</code>中，然后生成交易数据记录到 <code>pay_transaction</code>与<code>pay_transaction_extension</code> 中。</p> <p><strong>收到通知</strong>，记录数据到 <code>pay_log_data</code> 中，然后根据时支付的通知还是退款的通知，更新 <code>pay_transaction</code> 与 <code>pay_refund</code> 的状态。如果是重复支付需要记录数据到 <code>pay_repeat_transaction</code> 中。并且将需要通知应用的数据记录到 <code>pay_notify_app_log</code>，这张表相当于一个消息表，会有消费者会去消费其中的内容。</p> <p><strong>退款</strong> 记录日志日志到 <code>pay_log_data</code> 中，然后记录数据到退款表中 <code>pay_refund</code>。</p> <p>当然这其中还有些细节，需要大家自己看了表结构，实际去思考一下该如何使用。如果有任何疑问欢迎到我们GitHub的项目（点击阅读原文）中留言，我们都会一一解答。</p> <blockquote><p>这些表能够满足最基本的需求，其它内容可根据自己的需求进行扩张，比如：支持用户卡列表、退款走银行卡等。</p></blockquote> <h3 id="系统设计"><a href="#系统设计" class="header-anchor">#</a> 系统设计</h3> <p>这部分主要说下系统该如何搭建，以及代码组织方式的建议。</p> <h4 id="系统架构-2"><a href="#系统架构-2" class="header-anchor">#</a> 系统架构</h4> <p>由于支付系统的安全性非常高，因此不建议将对应的入口直接暴露给用户可见。应该是在自己的应用系统中调用支付系统的接口来完成业务。另外系统对数据要求是：强一致性的。因此也没有缓存介入（当如缓存可以用来做报警，这不在本文范畴）。</p> <p><img src="https://dayutalk.cn/img/image-20190309135800643.png" alt="image-20190309135800643"></p> <p>具体的实现，系统会使用两个域名，一个为内部使用，只有指定来源的ip能够访问固定功能（访问除通知外的其它功能）。另一个域名只能访问 <code>notify</code> <code>return</code> 两个路由。通过这种方式可以保证系统的安全。</p> <p>在数据库的使用上无论什么请求直接走 <strong>Master</strong> 库。这样保证数据的强一致。当然从库也是需要的。比如：账单、对账相关逻辑我们可以利用从库完成。</p> <h4 id="代码设计"><a href="#代码设计" class="header-anchor">#</a> 代码设计</h4> <p>不管想做什么最终都要用代码来实现。我们都知道需要可维护、可扩展的代码。那么具体到支付系统你会怎么做呢？我已支付为例说下我的代码结构设计思路。仅供参考。比如我要介入：微信、支付宝、招行 三家支付。我的代码结构图如下：</p> <p><img src="https://dayutalk.cn/img/image-20190309142925499.png" alt="image-20190309142925499"></p> <p>用文字简单介绍下。我会将每一个第三方封装成： <code>XXXGateway</code> 类，内部是单纯的封装第三方接口，不管对方是 HTTP 请求还是 SOAP 请求，都在内部进行统一处理。</p> <p>另外有一层<code>XXXProxy</code> 来封装这些第三方提供的能力。这一层主要干两件事情：对传过来请求支付的数据进行个性化处理。对返回的结构进行统一处理返回上层统一的结构。当然根据特殊情况这里可以进行一切业务处理；</p> <p>通过上面的操作变化已经基本上被完全封装了。如果新增一个支付渠道。只需要增加：<code>XXXGateway</code> 与 <code>XXXProxy</code>。</p> <p>那么 <code>Context</code> 与 <code>Server</code> 有什么用呢？<code>Server</code> 内部封装了所有的业务逻辑，它提供接口给 action 或者其它 server 进行调用。而 <code>Context</code> 这一层存在的价值是处理 <code>Proxy</code> 层返回的错误。以及在这里进行报警相关的处理。</p> <p>上面的结构只是我的一个实践，欢迎大家讨论。</p> <p>本文描述的系统只是满足了最基本的支付需求。缺少相关的监控、报警。如果你按照上文设计自己的系统，风险自担与我无关。</p> <h1 id="订单中心"><a href="#订单中心" class="header-anchor">#</a> 订单中心</h1> <p>请您耐心等待...</p> <h1 id="仓储系统"><a href="#仓储系统" class="header-anchor">#</a> 仓储系统</h1> <p>请您耐心等待...</p> <h1 id="物流系统"><a href="#物流系统" class="header-anchor">#</a> 物流系统</h1> <p>请您耐心等待...</p> <h1 id="售后服务"><a href="#售后服务" class="header-anchor">#</a> 售后服务</h1> <p>请您耐心等待...</p> <h1 id="基础服务"><a href="#基础服务" class="header-anchor">#</a> 基础服务</h1> <p>请您耐心等待...</p> <h1 id="skr-shop项目成员简介"><a href="#skr-shop项目成员简介" class="header-anchor">#</a> Skr Shop项目成员简介</h1> <p>排名不分先后，字典序</p> <table><thead><tr><th>昵称</th> <th>简介</th> <th>个人博客</th></tr></thead> <tbody><tr><td>AStraw</td> <td>研究生创业者</td> <td>公众号“稻草人生”</td></tr> <tr><td>大愚Dayu</td> <td>国内大多人使用的PHP第三方支付聚合项目<a href="https://github.com/helei112g/payment" target="_blank" rel="noopener noreferrer">Payment<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>作者，创过业</td> <td><a href="http://dayutalk.cn/" target="_blank" rel="noopener noreferrer">大愚Talk<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></td></tr> <tr><td>lwhcv</td> <td>曾就职于百度/融360</td> <td>--------</td></tr> <tr><td>TIGERB</td> <td>PHP框架<a href="http://easy-php.tigerb.cn/#/" target="_blank" rel="noopener noreferrer">EasyPHP<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>作者</td> <td><a href="http://tigerb.cn" target="_blank" rel="noopener noreferrer">TIGERB的技术博客<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></td></tr> <tr><td>Veaer</td> <td>宇宙无敌风火轮全干工程师</td> <td><a href="https://github.com/Veaer" target="_blank" rel="noopener noreferrer">Veaer<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></td></tr></tbody></table></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">7/20/2020, 2:09:44 AM</span></div></footer> <!----> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.cb35c8f6.js" defer></script><script src="/assets/js/2.063846a6.js" defer></script><script src="/assets/js/4.1ffb4609.js" defer></script><script src="/assets/js/255.64e680cb.js" defer></script>
  </body>
</html>
